Change Permissions on Files and Directories Using Alphabetic Notation


chmod [ugo][+-=][rwx]

You can use two notations with chmod: alphabetic or numeric. Both have their advantages, but it's sometimes easier for users to learn the alphabetic system first. Basically, the alphabetic method uses a simple formula: the user group you want to affect (u, g, o); followed by a plus sign (+) to grant permission, a minus sign () to remove permission, or an equal sign (=) to set exact permission; followed by the letters (r, w, x, s, t) representing the permission you want to alter. For instance, let's say you want to allow members of the family group to be able to change a picture.

$ ls -l -rw-r--r-- 1 scott family ... libby.jpg $ chmod g+w libby.jpg $ ls -l -rw-rw-r-- 1 scott family ... libby.jpg 


Easy enough. But what if you had wanted to give both the family group and all other users write permission on the file?

$ ls -l -rw-r--r-- 1 scott family ... libby.jpg $ chmod go+w libby.jpg $ ls -l -rw-rw-rw- 1 scott family ... libby.jpg 


Of course, because you're really giving all usersthe owner, the group, and the worldread and write access, you could have just done it like this:

$ ls -l -rw-r--r-- 1 scott family ... libby.jpg $ chmod a=rw libby.jpg $ ls -l -rw-rw-rw- 1 scott family ... libby.jpg 


You realize you made a mistake, and need to remove the capability of the family group and the world to alter that picture, and also ensure that the world can't even see the picture.

$ ls -l -rw-rw-rw- 1 scott family ... libby.jpg $ chmod go-w libby.jpg $ ls -l -rw-r--r-- 1 scott family ... libby.jpg $ chmod o-r libby.jpg $ ls -l -rw-r----- 1 scott family ... libby.jpg 


Instead of the -, you could have used the =:

$ ls -l -rw-rw-rw- 1 scott family ... libby.jpg $ chmod g=r libby.jpg $ ls -l -rw-r--rw- 1 scott family ... libby.jpg $ chmod o= libby.jpg $ ls -l -rw-r----- 1 scott family ... libby.jpg 


Notice on the last chmod that o equaled nothing, effectively removing all permissions for all other users on the system. Now that's fast and efficient!

The advantage to the alphabetic system is that it's often fast, but you can also see its main disadvantage in the last example: If you want to make changes to two or more user groups and those changes are different for each user group, you end up running chmod at least two times. The next section shows how numeric permissions get around that problem.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net