7

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?

3
  • 1
    You need permission to execute it as well. Do: chmod +x newfile in the same directory. Commented Feb 15, 2012 at 9:32
  • 2
    gcc should make executables, err, executable. What is your umask? Commented Feb 15, 2012 at 9:35
  • Why don't you increase your accepet rate? Start to accept the right anwsers or community will not help you no more. Commented Feb 16, 2012 at 8:07

2 Answers 2

12

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

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. But would please explain a bit more about this command?
Permissions in Linux (and probably most Unix-like systems) are represented by three bits : R, W, and X. If a file has the 'R' permission bit set, it is readable. If the 'W' bit is set, it is writeable. If the 'X' bit is set, it is executable. Unlike Windows, where the ability to execute a file is figured out according to the extension of the file, in Linux you can make every file executable simply by specifying the 'X' flag. Three permission bit sets are available : one for the owner of the file, second for the group which owns the file, and third one for everybody else.
"When you create a new file with gcc, by default, this isn't executable." ?? No, normally gcc creates executable files with x bit set. Rafi must have some weird setting that inhibits this.
Yes, you are right. I would say "your gcc" (by umask, i suppose) .. Now i'll edit
Besides umask there could be a filesystem-issue: Either the FS does not support Unix-Permissions (e.g. FAT, NTFS) or is configured to ignore them.
-1

After compiling, the file is placed in a.out Try to use a.out.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.