Parameters to be used with chmod?

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

kiki

Posted 2011-01-12T06:39:37.363

Reputation: 423

so wher shud i post these doubts then? – None – 2011-01-12T07:05:23.240

I think this question is acceptable since it's a shell issue. – chrisaycock – 2011-01-12T07:06:27.960

Answers

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

chrisaycock

Posted 2011-01-12T06:39:37.363

Reputation: 232

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.

Matthew Flaschen

Posted 2011-01-12T06:39:37.363

Reputation: 2 370

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 . – None – 2011-01-12T06:49:22.167

@kiki try going to the parent directory and doing chmod 777 on that. – barlop – 2011-01-12T09:20:41.320

1@kiki: Using 777 is almost always a bad idea for security. Only grant permissions that are actually needed. – Paused until further notice. – 2011-01-12T11:43:12.687

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.

Cirotix

Posted 2011-01-12T06:39:37.363

Reputation: 1