chmod –
Managing Permissions
Several different syntaxes can be
used with chmod. The first is to
enter
chmod entity = permissions filename at the shell prompt. You substitute u for Owner, g for Group, and o for Others in the entity portion of the
command. You substitute r, w, and/or x for
the permissions portion of the command. For example, suppose I wanted to
change the mode of contacts.odt to –rw–rw–r– –
(giving the Owner and Group read and
write permissions while giving Others only read access).
I would enter chmod u=rw,g=rw,o=r contacts.odt at the shell prompt (assuming the
file resides in the current directory). After I do so, the mode is adjusted
with the permissions assigned by chmod, as shown here:
openSUSE:/home/ksanders # chmod u=rw,g=rw,o=r contacts.odt
openSUSE:/home/ksanders # ls -l
contacts.odt
-rw-rw-r-- 1 ksanders users 0 Mar 18
08:02 contacts.odt
You can also use chmod to toggle a particular permission on or off using the
+ or – sign.
For example, suppose I want to turn off the write permission I just gave to
Group for the contacts.odt file.
I could enter chmod g–w contacts.odt at the shell prompt. When I do, the
specified permission is turned off, as shown next:
openSUSE:/home/ksanders # chmod g-w contacts.odt
openSUSE:/home/ksanders # ls -l
contacts.odt
-rw-r--r-- 1 ksanders users 0 Mar 18
08:02 contacts.odt
If I wanted to turn the permission
back on, I would enter chmod g+w
contacts.odt. You can substitute u or o, respectively, to modify the
permission to the file or directory for Owner or Others as well.
Finally, you can also use numeric
permissions with chmod. This is the
option I use most often.
You can modify all three entities at once with only three characters. To do
this, enter chmod <numeric_permission>
<filename>
.
Going back to our earlier example,
suppose I wanted to grant read and write permissions to Owner and Group, but
remove all permissions from Others. That would mean Owner and Group’s permissions
would be represented numerically as 6. Because Others gets no permissions, its
permissions would be represented by 0.
I could implement this by entering chmod 660 contacts.odt at the shell
prompt.
When I do, the appropriate changes
are made, as shown here:
openSUSE:/home/ksanders # chmod 660 contacts.odt
openSUSE:/home/ksanders # ls -l
contacts.odt
-rw-rw---- 1 ksanders users 0 Mar 18
08:02 contacts.odt
You can use the –R option with chmod
to change permissions on many files at once, recursively.
No comments:
Post a Comment