change file access permission

October 2nd, 2006 mysurface Posted in Admin, chmod | Hits: 28668 | 1 Comment »

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 myscript.sh

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 myscript.sh

To only gives executable mode for owner,

chmod u+x myscript.sh

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 myscript.sh

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 myscript.sh

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 myscript.sh

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

One Response to “change file access permission”

  1. I think this is among the so much important information for me.
    And i’m glad reading your article. But want to statement on some
    basic things, The website style is ideal, the articles is really excellent
    : D. Just right process, cheers

    website (Nilda)

Leave a Reply