Linux下文件权限更改
一,Linux下文件权限
使用ls -l可以查看文件及文件夹权限
drwxr-xr-x 4 lzt lzt 4096 7月 26 15:21 Downloads
-rw-rw-r-- 1 lzt lzt 526 6月 26 21:55 test.tpp
可以看出,文件或文件夹的权限是通过前面的10位来标示的
其中:
第1位:文件类型,d(directory)文件夹,-(file)文件
第2-4位:(user)所以者权限,w(write),r(read),x(execute)
第5-7位:(group)同组用户权限,w(write),r(read),x(execute)
第8-10位:(other)其他人的权限,w(write),r(read),x(execute)
二,Linux下文件权限修改
1.文字方式
chmod [who] [ + | - | = ] [mode] filename
who:u(user),g(group),o(other)
[ + | - | = ] :+(添加权限),-(取消权限),=(只给定该权限)
[mode]:r(可读),w(可写),x(可执行)
filename:文件名,多个以空格隔开
注:文件夹须加 -R
示例:
chmod -R g+x /home/lzt/Downloads
chmod o-x /home/lzt/test.tpp
2.数字方式
数字权限表示:4(read),2(write),1(execute),0(nothing)
文件权限表示:7(user)7(group)7(other)
所有权限 = 4 + 2 + 1 = 7
读写权限 = 4 + 2 + 0 = 6
其他权限类推
chmod [mode] filename
[mode]:766,766,其他
filename:文件名,多个以空格隔开
示例:
chmod -R 765 /home/lzt/Downloads
chmod 766 /home/lzt/test.tpp
来源: http://lib.csdn.net/article/linux/36347