查看文件权限
[root@localhost ~]# touch a.txt
[root@localhost ~]# ll a.txt
-rw-r--r-- 1 root root 0 Feb 15 07:52 a.txt
文件基本权限
- rwx r-x r-x user1 user1 FILENAME
类型 拥有者的权限 所属组的权限 其他人的权限 拥有者 属组 对象
对于文件:r读 w写 x执行
对于目录:r读(看到目录里面有什么) ls
w建文件、删除、移动 touch mkdir rm mv cp
x进入 cd
修改权限的相关命令:
chmod
作用:修改文件权限
u-w user 拥有者
g+x group 组
o=r other 其他人
a+x all 所有人
[root@localhost ~]# ll a.txt
-rw-r--r-- 1 root root 0 Feb 15 07:52 a.txt
[root@localhost ~]# chmod u-w a.txt
[root@localhost ~]# ll a.txt
-r--r--r-- 1 root root 0 Feb 15 07:52 a.txt
[root@localhost ~]# chmod g+x a.txt
[root@localhost ~]# ll a.txt
-r--r-xr-- 1 root root 0 Feb 15 07:52 a.txt
[root@localhost ~]# chmod o-r a.txt
[root@localhost ~]# ll a.txt
-r--r-x--- 1 root root 0 Feb 15 07:52 a.txt
[root@localhost ~]# chmod a=r a.txt
[root@localhost ~]# ll a.txt
-r--r--r-- 1 root root 0 Feb 15 07:52 a.txt
修改目录的权限
[root@localhost ~]# mkdir test
[root@localhost ~]# ll -d test/
drwxr-xr-x 2 root root 6 Feb 15 08:07 test/
[root@localhost ~]# chmod u-w test/
[root@localhost ~]# ll -d test/
dr-xr-xr-x 2 root root 6 Feb 15 08:07 test/
一次性修改多个权限:
[root@localhost ~]# chmod u=rwx a.txt
[root@localhost ~]# ll a.txt
-rwxr--r-- 1 root root 0 Feb 15 07:52 a.txt
使用数字表示权限
- rwx r-x r-x user1 user1 FILENAME
类型 拥有者的权限 所属组的权限 其他人的权限 属主 属组
rwx
r-- -w- --x
100 010 001 二进制 进制转换器
4 2 1 十进制
rw- 的值是多少? 4+2 = 6
r-x 4+1 = 5
rw-r--r-- 的值是多少? rw-=6 r--=4 r--=4 rw-r--r--=644
[root@localhost ~]# chmod 622 a.txt
[root@localhost ~]# ll a.txt
-rw--w--w- 1 root root 0 Feb 15 07:52 a.txt
[root@localhost ~]#
chown
作用:修改文件拥有者和所属组
语法:chown USER:GROUP 对象
chown USER 对象
chown :GROUP 对象
[root@localhost ~]# chown rm:bin a.txt
[root@localhost ~]# ll a.txt
-rw--w--w- 1 rm bin 0 Feb 15 07:52 a.txt
[root@localhost ~]# chown daemon a.txt
[root@localhost ~]# ll a.txt
-rw--w--w- 1 daemon bin 0 Feb 15 07:52 a.txt
[root@localhost ~]# chown :sys a.txt
[root@localhost ~]# ll a.txt
-rw--w--w- 1 daemon sys 0 Feb 15 07:52 a.txt
-R递归(目录下的所有内容全部更改,否则只修改目录)
[root@localhost ~]# chown rm test/ -R
[root@localhost ~]# ll -d test/
dr-xr-xr-x 2 rm root 30 Feb 15 08:21 test/
[root@localhost ~]# ll test/
total 0
网友评论