change file access permission

October 2nd, 2006 mysurface Posted in Admin, chmod | Hits: 27745 | No Comments »

chmod (change mode) is another very common and useful admin command, we usually use to change a file mode to executable when we are writting various script such as bash, python, perl, etc.

To change a file to executable,

chmod +x

By default, it change mode to all. The file mode is categories into 3,

u ( user – owner of the file)
g ( the user in the same file group)
o ( the other users)
a ( all above)

Therefore by default, command above is similar to

chmod a+x

To only gives executable mode for owner,

chmod u+x

You can remove mode from a file, let say by default the file have executable for ALL users, but you want to remove executable of OTHERS

chmod o-x

Besides execute mode, we have read and write, the same goes to these two mode.

For example I want to remove read write mode for OTHERS,

chmod o-rw

chmod can be done by specified numbers,
The numbers indicate the mode, shows as bellow:

execute = 1
write = 2
read = 4

Therefore read and write is 2+4 = 6, execute and read is 1+4 = 5.

To make the owner have rwx mode, but group and others have only rx, can do this,

chmod 755

So, 7= 4+2+1 (rwx) and 5 = 4+1 (rx).

Leave a Reply