Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing C program in Linux Terminal

Tags:

c

linux

terminal

I have compiled a program from my Ububtu 10.10 terminal by

gcc file_name.c -o new_file

command. It compiled successfully creating an executable file named new_file. But when I was trying to execute it by this command

./new_file

It says that permission is denied of new_file. I've checked the permission properties of that file found that I've permission to read & write it (I'm the only user of that system). Can you please help me to figure out the problem?

like image 932
Rafi Kamal Avatar asked Feb 15 '12 09:02

Rafi Kamal


1 Answers

You have to give it exe. permissions.

So: chmod +x new_file

When you create a new file with your gcc, by default, this isn't executable. So, you have to gave it permissions of execution.

With chmod (see this) you change permissions on file.

In that specific case, you gave execution permissions ( + [plus] means gave, 'x' means execution ) to that file.

If you want to revoke that permission, you can type: chmod -x filename

like image 91
DonCallisto Avatar answered Nov 08 '22 16:11

DonCallisto