Читать книгу Linux Bible - Christopher Negus - Страница 135
Setting default file permission with umask
ОглавлениеWhen you create a file as a regular user, it's given permission rw-rw-r--
by default. A directory is given the permission rwxrwxr-x
. For the root user, file and directory permission are rw-r--r--
and rwxr-xr-x
, respectively. These default values are determined by the value of umask
. Enter umask to see what your umask
value is. For example:
$ umask 0002
If you ignore the leading zero for the moment, the umask
value masks what is considered to be fully opened permissions for a file 666 or a directory 777. The umask
value of 002 results in permission for a directory of 775 (rwxrwxr-x
). That same umask
results in a file permission of 644 (rw-rw-r--
). (Execute permissions are off by default for regular files.)
To change your umask
value temporarily, run the umask
command. Then try creating some files and directories to see how the umask
value affects how permissions are set. For example:
$ umask 777 ; touch file01 ; mkdir dir01 ; ls -ld file01 dir01 d---------. 2 joe joe 6 Dec 19 11:03 dir01 ----------. 1 joe joe 0 Dec 19 11:02 file01 $ umask 000 ; touch file02 ; mkdir dir02 ; ls -ld file02 dir02 drwxrwxrwx. 2 joe joe 6 Dec 19 11:00 dir02/ -rw-rw-rw-. 1 joe joe 0 Dec 19 10:59 file02 $ umask 022 ; touch file03 ; mkdir dir03 ; ls -ld file03 dir03 drwxr-xr-x. 2 joe joe 6 Dec 19 11:07 dir03 -rw-r--r--. 1 joe joe 0 Dec 19 11:07 file03
If you want to change your umask
value permanently, add a umask
command to the .bashrc
file in your home directory (near the end of that file). The next time you open a shell, your umask
is set to whatever value you chose.