专家级用户喜欢用一个八进制数来表示文件的权限,而不是用户符号(Owner, User, Group)和权限符号(Read, Write, eXecution).
1. 八进制数字包括3个数字,从左到右代表所有者权限、组权限、其它用户权限,数字越大,权限越大。
$ chmod 700 * //为文件拥有者设置读、写和执行权限;
$ ls -l
total 0
-rwx------ 1 root other 0 Apr 24 11:02 test
# chmod 770 * //为文件拥有者及组成员设置读、写和执行权限;
# ls -l
total 0
-rwxrwx--- 1 root other 0 Apr 24 11:02 test
# chmod 777 * //为文件拥有者、组成员及所有用户设置读、写和执行权限;
# ls -l
total 0
-rwxrwxrwx 1 root other 0 Apr 24 11:02 test
# chmod 000 * //取消所有权限;
# ls -l
total 0
---------- 1 root other 0 Apr 24 11:02 test
2. 设置默认权限umask
umask将对具体用户创建的所有新文件 设置读、写和执行权限。因此用户可以在用户的Shell启动文件如.bashrc中设置umask,或者在全局系统默认文件/etc/default/login中设置。
同文件权限一样,umask使用八进制代码表示 ,但计算有两种不同方法:
(a) 对目录,必须从777中减去想设置的默认权限的八进制值;
(b)对文件,必须从666中减去想设置的默认权限的八进制值;
例如,想要所有的用户对你所创建的任何文件都有完全的访问权限,可以用umask 000
#umask 000
# touch test.txt
# ls -l
total 0
-rw-rw-rw- 1 root other 0 Apr 24 11:14 test.txt
【奇怪,有点不一样,上面的权限只有读写】
一般情况下,更为用umask 022,表示新文件权限是755(777-022=755),表示文件拥有者有RWX权限,而组成员和其它用户只有R权限。
# umask 022
# touch test1
# ls -l
total 0
-rw-rw-rw- 1 root other 0 Apr 24 11:14 test
-rw-rw-rw- 1 root other 0 Apr 24 11:14 test.txt
-rw-r--r-- 1 root other 0 Apr 24 11:16 test1
#umask 077 //只给文件所有者设置RWX权限,其它用户无权限
另:umask不会影响以前已经创建的其它文件的权限,只影响以后创建的文件。