Set UNIX file access permissions with chmod
UNIX operating systems enforce strict access control of files based on the owner, a group, and everyone else. This recipe describes the techniques for setting these access control s with chmod.
The UNIX chmod command can be confusing until a few basic points are explained. It allows different access control for the owner of the file u, a specific group of users on the system g, and everyone else o.
There are three different permissions that can be assigned to the users above. Read r, write w, and execute x. As a shortcut, all of these permissions can be represented by a.
Composing a chmod command requires putting together the user(s) affected, a plus or minus to add or remove the permission(s), and the permissions to change. The following summarizes these:
g group +/- w write a all
o other x execute
When a long listing is made of a file, the first part of the listing shows the permissions of the file, for example -rwxr-x---. The first character indicates if the item listed is a directory (with the letter d there) or a file (with a - as shown in this example. The next three characters (rwx) are the permissions for the owner of the file (read, write, and execute in this example). The next three (r-x) are the group permisisons (read and execute). The last three (---) are permissions for other (anyone else) and indicates no permissions.
Now the chmod command now becomes simple as long as you keep in mind what you are trying to accomplish. For example, the requirement "allow other people read access to myfile" can be accomplished by:
Multple characters can be placed on either side of the +/- to perform more complex changes. The requirement "allow the owner and group members of thefile to read and write to thefile" becomes:
Some more examples:
chmod go-a file remove all permissions to group and other
chmod +r file add read permissiosn to everyone (u, g, o)
chmod o+x dir allow others to cd into directory
Note that an x permission on a directory allows the affected users to be able to change into that directory.
Changed in permissions can be chained together in a single command, so to add read and write to owner, read only to group, and other no access to the file bigfile:
Once you have a handle on this syntax for chmod and are ready for another powerful way to use the command, check out the recipe advanced octal file permissions with chmod.
Also see ...
H3The chmod command in various UNIX flavors like Solaris, Linux, Mac OSX, and others, allows the access controls of a file or directory to be set. This recipe describes the more complex octal chmod syntax./H3PSee the recipe a href="unix_tips691.html" target="_blank" class="postlink" rel="nof
H3This tip is for grepping a pattern even in the sub directories of a particular directory in addition to the files in the current directory. Since grep R is not available on all flavors, this can be really helpful./H3PThe command is as follows : br / br /div class="code"find
H3This recipe is useful when one wants to kill all the processes belonging to one user or having a particular regular expression in the process name. One can use different options of "ps" and "grep" to kill the undesired process(es)./H3PThe following is the general syntax of this recipe b
H3I have used this quite a bit and it works great for me. We're on an HP box running Unix 11.11. You can embed javascripts, css, etc. Pretty cool stuff. /H3Pdiv class="code"&40; br /echo "From&58; you@your_company.com" br /echo "To&58; you@your_company.com" br
H3Copy and rename a file in a shorter step than the normal cp file file.bak/H3PIf you have a file named foobar and you want to make a backup copy named foobar.bak you could do br / br /div class="code"cp foobar foobar.bakP br /but what if the file has a long name, and you have
