Sunday, September 27, 2009

Ubuntu File Permissions and recursively changing file permissions:

To change file permissions of a particular folder and folders/files under it recursively to read write execute, the shell command is :

sudo chmod 777 -R /path/tothe/particularfile-folder/

The first 7 determines that it is intended for this "user"(current user)....
The second 7 determines that it is intended for this "group"(current user group or a particular group)....
The third 7 determines that it is intended for "others"....

Now what is the fuss about "7"?/ u guys might be wondering. This has significance.

All Unix like systems have the following standard to represent RWX(read-write-execute)for a user/groups/other users in the system:

4- Read(can only read).

2- Write(can only write).

1- Execute(can only execute).

so, if you want to give a current user only execute rights you say:
sudo chmod 177 blah/blah

but if you want to give read and execute you give (1 + 4 = 5):

sudo chmod 577 blah/blah/topath

if you want to give read and write to a user group and others but not execute you give (4 + 2 = 6):

sudo chmod 166 blah/blah/topath

so far i guess you must have figured out that

1+4= 5 (gives execute and read rights but not write rights)

1+2= 3 (gives execute and write rights but not read rights)

4+2= 6 (gives read and write rights but not execute rights)

4+2+1=7 (gives read write and execute rights).....

you can use the above commands for recursively or just changing folder permissions, file permissions......

just chill whenever you see a 7,3,6,5 in a chmod or in any other command.....its determining the UGO(User Group and Other) rights/or what so ever..........


No comments:

Post a Comment