Cannot open the output file a.out: Permission denied, on a simple compilation

I wrote the code in vim and whenever I try to run the code, it shows this:

coolmego@coolmego-PC:~/coolmego/cprograms$ gcc dfs8puzz.c 
/usr/bin/ld: cannot open output file a.out: Permission denied
collect2: ld returned 1 exit status
coolmego@coolmego-PC:~/coolmego/cprograms$ ./a.out
bash: ./a.out: No such file or directory

What should I do?

+3
source share
4 answers

Move to the directory where you are allowed to write.

+7
source

When you run sudo, you actually execute the commands as the root user. You might end up messing up the permissions so that root owns the files. Thus, when you run sudo, it just works (root can write to these directories). You need coolmego to own these files. For instance:

sudo chown coolmego /home/coolmego/coolmego/cprograms/
chmod 700 /home/coolmego/coolmego/cprograms/
0
source

/etc/fstab. , fstab, noexec, exec fstab.

0

chmod -R 777 ~/coolmego/cprograms

-4

All Articles