1

How to use CHMOD in linux? When I try to delete a file/folder, permission is denied. What exact params must I give for chmod here?

This is what I need to do. Execute a command ./build.mips , but I get permission denied error.

kirti@sgf:/disk/go$./build.mips
-bash: ./build.mips: Permission denied
2
  • so wher shud i post these doubts then?
    – kiki
    Jan 12, 2011 at 7:05
  • I think this question is acceptable since it's a shell issue. Jan 12, 2011 at 7:06

3 Answers 3

3

If you can't delete a file even after you've chmod'ed it to 777, the problem may be with the directory that the file is in. For example:

# no permission to write in the current directory...
$ ls -la
total 0
dr-xr-xr-x   3 chrisaycock  staff   102 Jan 12 02:00 ./
drwxr-xr-x+ 59 chrisaycock  staff  2006 Jan 12 01:59 ../
-rw-r--r--   1 chrisaycock  staff     0 Jan 12 02:00 test.txt

# ... and thus I can't delete a file in this directory
$ rm test.txt
rm: test.txt: Permission denied

# so I give myself permission to write
$ chmod u+w .

# just to confirm that I can write in this directory
$ ls -la
total 0
drwxr-xr-x   3 chrisaycock  staff   102 Jan 12 02:00 ./
drwxr-xr-x+ 59 chrisaycock  staff  2006 Jan 12 01:59 ../
-rw-r--r--   1 chrisaycock  staff     0 Jan 12 02:00 test.txt

# and now I can remove the file
$ rm test.txt
1

If you want to be able to run the program, run:

chmod a+x ./build.mips

Of course, you must have permission to do that.

3
  • how to get the permission is my question..also, when I try to delete a directory, i get permission denied. Even after i give chmod -c 777 .
    – kiki
    Jan 12, 2011 at 6:49
  • @kiki try going to the parent directory and doing chmod 777 on that.
    – barlop
    Jan 12, 2011 at 9:20
  • 1
    @kiki: Using 777 is almost always a bad idea for security. Only grant permissions that are actually needed. Jan 12, 2011 at 11:43
0

To delete files or folder it is much easier to gain root permission to delete it than to chmod (or chown) it before deletion.

you can do (if you need only one command with root permission. You need to configure your sudo to do that, depending of your Linux distribution)

$ sudo rm test.txt

or

$ su (prompt to type the root password)
# rm test.txt
# exit (or CRTL+D)

or (if no root user on the machine)

$ sudo -s
# rm test.txt
# exit

Use the same procedures to chmod files that you don't own.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .