Running a C program in a Linux terminal

I compiled a program from my Ububtu 10.10 terminal

gcc file_name.c -o new_file

teams. He compiled the successful creation of an executable file called new_file. But when I tried to execute it with this command

 ./new_file 

It says that permission is forbidden for new_file. I checked the permission properties of this file, which found that I have read and write permission (I am the only user of this system). Could you help me deal with the problem?

+6
source share
2 answers

You have to give him exe. permissions.

So: chmod +x new_file

When you create a new file with your gcc, this is not possible by default. Therefore, you must grant him permission to execute.

With chmod (see this) you change file permissions.

In this particular case, you have granted execution permissions (+ [plus] means “x” means execution) to this file.

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

+11
source

After compilation, the file is placed in a.out Try using a.out .

-1
source

Source: https://habr.com/ru/post/908495/


All Articles