2024年11月26日 Linux chmod命令 极客笔记
Linux chmod命令:更改文件和目录的模式。
使用chmod命令可以更改文件和目录的模式,以达到修改文件访问权限的效果。
chmod [选项] [模式][文件]
chmod [选项][八进制模式] [文件]
chmod [选项] [文件]
命令中各选项的含义如下表所示。
更改文件和目录的模式有两种方法:文件设定法和数字设定法。
文件设定法使用下表所示内容进行设置,完整的设置应该包含操作对象、操作符号和权限。
[root@rhel ~]# chmod u+w ah
[root@rhel ~]# chmod u-r ah
[root@rhel ~]# chmod g=w ah
[root@rhel ~]# chmod u+rw, g+r, o+rwx ah
[root@rhel ~]# chmod a-rwx ah
文件和目录的权限表中用r、w、x这3个字符来为用户所有者、组群所有者和其他用户设置权限。有时候,字符似乎过于麻烦,因此还有另外一种方法是以数字来表示权限,而且仅需3个数字。
使用数字设定法更改文件权限,首先必须了解数字表示的含义:0表示没有权限,1表示可执行权限,2表示写入权限,4表示读取权限,然后将其相加。
所有数字属性的格式应该是3个0~7的数,其顺序是u、g、o。
例如,如果想让某个文件的所有者有“读/写”两种权限,需要用数字6来表示,即4(可读)+2(可写)=6(读/写)。
[root@rhel ~]# chmod 700 ah
[root@rhel ~]# chmod 470 ah
[root@rhel ~]# chmod 777 ah
[root@rhel ~]# chmod 7 ah
[root@rhel ~]# chmod -R 777 /home/user
[root@rhel ~]# chmod u+s ah
[root@rhel ~]# chmod g+s ah
[root@rhel ~]# chmod o+t ah
[root@rhel ~]# chmod 4000 ah
[root@rhel ~]# chmod 2000 ah
[root@rhel ~]# chmod 1000 ah
[root@rhel ~]# chmod 7000 ah
本文链接:http://so.lmcjl.com/news/18540/