文件权限管理

设置目录和普通文件的权限---chmod

chmod设置权限主要是设置属主,属组,其他用户对于文件或目录读(r),写(w),执行(x)的权限,即图中红框部分。

chmod设置文件或目录权限有两种方式

chmod   [ugoa][+-][rwx]   文件或目录名

u:代表文件的属主

[root@sunny test]# chmod u+x 1.txt
[root@sunny test]# ll
total 0
-rwxr--r--. 1 root root 0 Aug  9 22:52 1.txt
[root@sunny test]# chmod u-rx 1.txt
[root@sunny test]# ll
total 0
--w-r--r--. 1 root root 0 Aug  9 22:52 1.txt

g:代表文件的属组

[root@sunny test]# chmod g+wx 1.txt
[root@sunny test]# ll
total 0
--w-rwxr--. 1 root root 0 Aug  9 22:52 1.txt
[root@sunny test]# chmod g-wx 1.txt
[root@sunny test]# ll
total 0
--w-r--r--. 1 root root 0 Aug  9 22:52 1.txt

o:代表其他用户

[root@sunny test]# chmod o+wx 1.txt
[root@sunny test]# ll
total 0
--w-r--rwx. 1 root root 0 Aug  9 22:52 1.txt
[root@sunny test]# chmod o-wx 1.txt
[root@sunny test]# ll
total 0
--w-r--r--. 1 root root 0 Aug  9 22:52 1.txt

a:默认选项,代表所有用户

[root@sunny test]# chmod a+x 1.txt
[root@sunny test]# ll
total 0
--wxr-xr-x. 1 root root 0 Aug  9 22:52 1.txt
[root@sunny test]# chmod a-x 1.txt
[root@sunny test]# ll
total 0
--w-r--r--. 1 root root 0 Aug  9 22:52 1.txt

rwx,可以看作三位二进制数,有权限则当位为1,没有权限则当位为0,那么可读可写可操作则为(111)2转换成十进制即为7

若设置所有用户都有可读可写可操作的权限,就可以输入如下的命令

[root@sunny test]# chmod 777 1.txt
[root@sunny test]# ll
total 0
-rwxrwxrwx. 1 root root 0 Aug  9 22:52 1.txt

若仅有属主有可读可写可操作的权限,除属主外的用户对文件没有任何权限,则可输入下面的命令

[root@sunny test]# chmod 700 1.txt
[root@sunny test]# ll
total 0
-rwx------. 1 root root 0 Aug  9 22:52 1.txt

设置目录文件的归属---chown,chgrp

设置目录文件的归属,即设置上图红框中的内容,用到的命令有:chown,chgrp

chown  属主  文件或目录

[root@sunny test]# chown sl010 1.txt
[root@sunny test]# ll
total 0
-rwx------. 1 sl010 root 0 Aug  9 22:52 1.txt

chgrp  属组  文件或目录

[root@sunny test]# chgrp sl011 1.txt
[root@sunny test]# ll
total 0
-rwx------. 1 sl010 sl011 0 Aug  9 22:52 1.txt

chown  属主:属组  文件或目录  /  chown  属主.属组  文件或目录

[root@sunny test]# chown root:root 1.txt
[root@sunny test]# ll
total 0
-rwx------. 1 root root 0 Aug  9 22:52 1.txt
[root@sunny test]# chown sl011.sl011 1.txt
[root@sunny test]# ll
total 0
-rwx------. 1 sl011 sl011 0 Aug  9 22:52 1.txt

-R:递归修改指定目录下所有子目录机文件的归属

[root@sunny mnt]# chown sl011.sl011 -R test
[root@sunny mnt]# ll -R
.:
total 0
drwxr-xr-x. 3 sl011 sl011 45 Aug  9 22:53 test

./test:
total 0
-rwx------. 1 sl011 sl011 0 Aug  9 22:52 1.txt
-rw-r--r--. 1 sl011 sl011 0 Aug  9 22:52 2.txt
drwxr-xr-x. 2 sl011 sl011 6 Aug  9 22:53 test1

./test/test1:
total 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值