改变权限
读取(r)、写入(w)和执行(x)
可以使用 chmod (change mode) 命令来改变文件或目录的访问权限,权限可以使用符号或数字来表示。
符号 说明
+ 为文件或目录增加权限
- 删除文件或目录的权限
= 设置指定的权限
例子:
$ls -l testfile
-rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile
$chmod o+wx testfile
$ls -l testfile
-rwxrwxrwx 1 amrood users 1024 Nov 2 00:10 testfile
$chmod u-x testfile
$ls -l testfile
-rw-rwxrwx 1 amrood users 1024 Nov 2 00:10 testfile
$chmod g=rx testfile
$ls -l testfile
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile
$chmod g=rx testfile
$ls -l testfile
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile
使用数字表示权限:
数字 说明 权限
0 没有任何权限 —
1 执行权限 –x
2 写入权限 -w-
3 执行权限和写入权限:1 (执行) + 2 (写入) = 3 -wx
4 读取权限 r–
5 读取和执行权限:4 (读取) + 1 (执行) = 5 r-x
6 读取和写入权限:4 (读取) + 2 (写入) = 6 rw-
7 所有权限: 4 (读取) + 2 (写入) + 1 (执行) = 7 rwx
$ls -l testfile
-rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile
$ chmod 755 testfile
$ls -l testfile
-rwxr-xr-x 1 amrood users 1024 Nov 2 00:10 testfile
$chmod 743 testfile
$ls -l testfile
-rwxr---wx 1 amrood users 1024 Nov 2 00:10 testfile
$chmod 043 testfile
$ls -l testfile
----r---wx 1 amrood users 1024 Nov 2 00:10 testfile