Читать книгу Linux Bible - Christopher Negus - Страница 133
Changing permissions with chmod (numbers)
ОглавлениеIf you own a file, you can use the chmod
command to change the permission on it as you please. In one method of doing this, each permission (read, write, and execute) is assigned a number—r=4, w=2, and x=1—and you use each set's total number to establish the permission. For example, to make permissions wide open for yourself as owner, you would set the first number to 7 (4+2+1), and then you would give the group and others read-only permission by setting both the second and third numbers to 4 (4+0+0), so that the final number is 744. Any combination of permissions can result from 0 (no permission) through 7 (full permission).
Here are some examples of how to change permission on a file (named file
) and what the resulting permission would be:
The following chmod
command results in this permission: rwxrwxrwx
# chmod 777 file
The following chmod
command results in this permission: rwxr-xr-x
# chmod 755 file
The following chmod
command results in this permission: rw-r--r--
# chmod 644 file
The following chmod
command results in this permission: ---------
# chmod 000 file
The chmod
command also can be used recursively. For example, suppose that you wanted to give an entire directory structure 755 permission (rwxr-xr-x
), starting at the $HOME/myapps
directory. To do that, you could use the -R
option, as follows:
$ chmod -R 755 $HOME/myapps
All files and directories below, and including, the myapps
directory in your home directory will have 755 permissions set. Because the numbers approach to setting permission changes all permission bits at once, it's more common to use letters to change permission bits recursively over a large set of files.