The chmod command is used to change the permissions on a file. Let's start our discussion of chmod with the listing of the file sort shown earlier: $ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort Figure 21-5 shows a breakdown of the permissions on sort . Figure 21-5. Permissions of File sort
You have very little control over the type of file defined. You do, however, have a great deal of control over the permissions of this file if it belongs to you. The chmod command is used to change the permissions on a file or directory. If you are the owner of the file, you can have a field day changing the permissions on the file. There are two means by which you can change the permissions: symbolic or numeric. I focus first on the numeric mode, because the numbers involved are easy to manage and I sometimes find that new UNIX users get hung up on the meaning of some of the symbols. I'll then cover the symbols and include the symbol meanings in the chmod summary. I decided to use the symbols in the summary because the numeric mode, which I much prefer, is becoming obsolete. In some UNIX variants, the chmod manual page is strewn with references to "obsolescent form" whenever the numeric mode is covered. First of all, what do I mean by numbers? Looking at the numbers for sort , we see permissions of 751: 7 for owner (hundreds position), 5 for group (tens position), and 1 for other (ones position). Figure 21-6 helps with the meanings of the positions : Figure 21-6. Numerical Permissions Summary
Selecting the desired permissions for owner , group , and other, you use the chmod command to assign those permissions to a file or directory. Some of these permission possibilities are infrequently used, such as execute only, because you usually need to have read access to a file in order to execute it; however, I included all possibilities in Figure 21-6 for completeness. In addition to the permission mode bits shown in figure 21-6, some miscellaneous mode bits also exist that you don't need to be concerned with at this time. If you decided that you would like to add write permission of the file sort for group and remove all permissions for other , you would simply execute the chmod command with the appropriate numeric value. The following set of commands first lists the existing permissions for sort , then it changes the permissions on sort , and finally it lists the new permissions on sort : $ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort $ chmod 770 sort $ ls -l sort -rwxrwx--- 1 marty users 120 Jul 26 10:20 sort The same set of commands to change the permissions using the symbolic mode would be: $ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort $ chmod g+w,o-x sort $ ls -l sort -rwxrwx--- 1 marty users 120 Jul 26 10:20 sort In symbolic mode, you issue the chmod command and specify who will be affected by the change [ user (u), group (g), other (o), or all (a)], the operation you wish to perform [add (+), delete (-), or replace (=)] on permissions, and the permission you wish to specify [read (r), write (w), or execute (x)]. In the previous example using symbolic mode, write (w) permission is being added (+) for group (g), and execute (x) permission is being removed (-) for other (o). The following is a summary of some of the more commonly used symbols of chmod : chmod - Change permissions of specified files using the following symbolic mode list.
|