|
|
To change the permissions on a file, you use the command chmod. (chmod stands for ``change mode;'' a file's permissions are also known as its mode.) As with chown, and chgrp, only the owner of a file or the superuser (root) can change the permissions of a file.
To change the permissions on the file, type chmod, how you want to change the permissions, the name of the file, then press <Enter>.
To specify how you want to change permissions, you type a letter representing which set of permissions you want to change, a symbol that tells whether you want to add to, remove from, or overwrite the existing permissions, and a letter representing which permission you want to work with.
For example, to change the permissions on the file report so that members of the group techpubs can modify the file, you could type:
$The chmod command in the preceding example says ``group plus write''; in other words, add write permission to the existing permissions for group. If you wanted to remove the group write permission, you could type:l report
-rw-r----- 1 susannah techpubs 25 Jun 27 11:58 report $chmod g+w report
$l report
-rw-rw---- 1 susannah techpubs 25 Jun 27 11:58 report
$If you wanted to remove all permissions for group, you could type:l report
-rw-rw---- 1 susannah techpubs 25 Jun 27 11:58 report $chmod g-w report
$l report
-rw-r----- 1 susannah techpubs 25 Jun 27 11:58 report
$The equals sign in the second example says ``overwrite all group permissions with nothing''; in other words, remove all group permissions.l report
-rw-rw---- 1 susannah techpubs 25 Jun 27 11:58 report $chmod g= report
$l report
-rw------- 1 susannah techpubs 25 Jun 27 11:58 report
You can think of how you specify permissions as an expression of the form:
chmod who [+|-|=] permission filename
Here, who tells which set of permissions you want to change; + , -, or = tells whether you want to add, remove, or overwrite; permission is the permission itself, and filename is the name of the file.
Here are all the options for who:
Option | Meaning |
---|---|
a | All users; change all three sets of permissions at once |
u | User; change the user, or owner, permissions |
g | Group; change the group permissions |
o | Others; change the other permissions |
Try creating a report file and then changing the permissions, the ownership, and the group it is in:
$cd
$cat > test This is a test file
<Ctrl>D
$l test
-rw-rw---- 1 susannah techpubs 20 Jun 27 15:40 test $chmod +rw test
$l test
-rw-rw-rw- 1 susannah techpubs 20 Jun 27 15:40 test $chmod o-w test
$chmod g-w test
$l test
-rw-r--r-- 1 susannah techpubs 20 Jun 27 15:40 test $chown root test
$l test
-rw-r--r-- 1 root techpubs 20 Jun 27 15:40 test
"test" [Read only]
at the bottom of
your screen.
This is because you are no longer the owner of the file, so you
only have read permission on it.
(If you were to make changes to the file, when you tried to save it, you
would see the error message
File is read only
; you would not be able to save your changes.)
Type :q to quit vi.