Sunday, May 16, 2010

Linux/Unix chmod (chmod xxx file)

Here I'm giving a brief explanation on how to changes the permission of a file in Linux/Unix system.

Syntax;
chmod [numeric number] [file]

here [numeric number] is created using the following criteria.


owner
(User who owns the file.)
group
(Group that owns the file.)
anybody
(Other)
non 0 0 0
read 4 4 4
write 2 2 2
execute 1 1 1

so its easy.
if you want only read by owner;
chmod 400 file

if only executed by others
chmod 001 file

if read/write by the owner and only read by everyone else
chmod (4+2)(4)(4)  file
which is;
chmod 644 file

With this if all need executable rights
chmod (4+2+1)(4+1)(4+1)  file
that's it;
chmod 755 file

This can also be calculated in a more professional way.

when we are checking the permissions of files using "ls -l" command in the terminal we get a results which looks like "- rwx r-x r-- file ".
this can be interpreted as;
- rwx r-x r-- file 
--111 101 100
here;
    r  read
    w  write
    x executable
    - non
 
Where now when we convert each set binary digits to decimal,
BinaryDecimal
0000
0011
0102
0113
BinaryDecimal
1004
1015
1106
1117

We get the numeric values we wonted. In this case its 754
So we have to use the command.
chmod 754 file

2 comments:

  1. Macho, this is really useful. I wanted to know what these numbers are from a long time but never had time to look for it. thanks...!

    ReplyDelete
  2. An excellent information provided thanks for all the information i must say great efforts made by you. thanks a lot for all the information you provided.

    Dietplanpdf.com
    Ketosidedishes.com

    ReplyDelete