linux系统中chmod命令

1、linux系统中文件和目录的权限

按照用户可分为所有者、所属组和其他人。

所有者用u代表(user)

所属组用g代表(group)

其他人用o代表(other)

按照具体的权限可以分为可读、可写、可执行、无权限

可读用r代表(read),用数字4表示

可写用w代表(write),用数字2表示

可执行用x代表(execute?),用数字1表示

 

2、linux中使用ll -l 、ls -l 、ls  -ld等命令查看文件或目录权限

例如:

[root@linuxprobe test]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 20 20:59 a.txt
drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01

 

 

3、linux系统中使用chmod命令修改文件和目录的权限

用法chmod  [选项} 文件,示例:

[root@linuxprobe test]# ll
total 0
-rw-r--r--. 1 root root 0 Oct 20 20:59 a.txt
drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod u+x a.txt  ## 所有者增加执行权限
[root@linuxprobe test]# ll
total 0
-rwxr--r--. 1 root root 0 Oct 20 20:59 a.txt
drwxr-xr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod u-x,g+w test01/  ## 所有者减去执行权限,同时所属组增加写得全选
[root@linuxprobe test]# ll
total 0
-rwxr--r--. 1 root root 0 Oct 20 20:59 a.txt
drw-rwxr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod u=rw,g=r,o=x a.txt  ## 直接按照所有者、所属组、其他人赋予权限
[root@linuxprobe test]# ll
total 0
-rw-r----x. 1 root root 0 Oct 20 20:59 a.txt
drw-rwxr-x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod 421 test01/   ## 直接使用数字赋予权限 4表示所有者有读的权限,2表示所属组有写的权限,1代表其他人具有执行的权限
[root@linuxprobe test]# ll
total 0
-rw-r----x. 1 root root 0 Oct 20 20:59 a.txt
dr---w---x. 2 root root 6 Oct 20 21:00 test01
[root@linuxprobe test]# chmod 777 a.txt  ## 所有者、所属组、其他人都具有可读、可写、可执行的权限
[root@linuxprobe test]# ll
total 0
-rwxrwxrwx. 1 root root 0 Oct 20 20:59 a.txt
dr---w---x. 2 root root 6 Oct 20 21:00 test01

 

3、修改目录权限时,加 -R参数表示递归

[root@linuxprobe test]# mkdir test01 test02  ## 测试目录
[root@linuxprobe test]# touch test01/a.txt   ##测试文件
[root@linuxprobe test]# touch test02/b.txt   ##测试文件
[root@linuxprobe test]# ll
total 0
drwxr-xr-x. 2 root root 18 Oct 20 21:15 test01
drwxr-xr-x. 2 root root 18 Oct 20 21:15 test02
[root@linuxprobe test]# ls -l test01/a.txt
-rw-r--r--. 1 root root 0 Oct 20 21:15 test01/a.txt
[root@linuxprobe test]# ls -l test02/b.txt
-rw-r--r--. 1 root root 0 Oct 20 21:15 test02/b.txt
[root@linuxprobe test]# chmod 777 test01/  
[root@linuxprobe test]# chmod -R 777 test02/  ## 添加 -R参数
[root@linuxprobe test]# ll
total 0
drwxrwxrwx. 2 root root 18 Oct 20 21:15 test01
drwxrwxrwx. 2 root root 18 Oct 20 21:15 test02
[root@linuxprobe test]# ls -l test01/a.txt
-rw-r--r--. 1 root root 0 Oct 20 21:15 test01/a.txt
[root@linuxprobe test]# ls -l test02/b.txt   ## test02目录下的b.txt也赋予了777的权限
-rwxrwxrwx. 1 root root 0 Oct 20 21:15 test02/b.txt

 

posted @ 2020-10-20 21:12  小鲨鱼2018  阅读(679)  评论(0编辑  收藏  举报