Linux权限处理常用的四个命令详解

原创Blog,转载请注明出处

http://blog.csdn.net/hello_hwc?viewmode=contents

权限

对于文件
r 可读
w 可写
x 可执行
对于目录
r 可以列出目录的内容(ls)
w 可以在目录中创建和删除文件(touch/rm)
x 可以进入目录(cd)


一、chmod
chmod用来改变权限
常用的方式
1、用ugo+rwx 或者ugo-rwx或者ugo=rwx改变权限
这里的ugo
u 用户
g 用户组
o 其他人
比如:ug+x 就是为用户和用户组增加可执行权限
举例:
[root@localhost testForCsdn]# ls -l testfile 
-rw-r----- 1 root root 0 Nov  1 22:14 testfile

为其他人赋予读写权限
[root@localhost testForCsdn]# chmod o=rw testfile 
[root@localhost testForCsdn]# ls -l testfile 
-rw-r--rw- 1 root root 0 Nov  1 22:14 testfile

为其他人去掉写的权限
[root@localhost testForCsdn]# chmod o-w testfile 
[root@localhost testForCsdn]# ls -l testfile 
-rw-r--r-- 1 root root 0 Nov  1 22:40 testfile

为用户组添加写的权限
[root@localhost testForCsdn]# chmod g+w testfile 
[root@localhost testForCsdn]# ls -l testfile 
-rw-rw-r-- 1 root root 0 Nov  1 22:40 testfile

2、用数字的方式改变权限
r对应4
w对应2
x对应1
比如:5=4+1 那么5代表的就是可读和可执行权限
举例
创建一个空文件,并且查看权限,可以看到,当前权限是rw-r--r--
也就是说:
对说有着来说是rw- 可读可写不可执行
对所属组来说是r-- 只可写
对其他人来说是r-- 只可写
举例
创建一个脚本,并且赋予它所有者的可执行权限
[root@localhost testForCsdn]# touch test.script
[root@localhost testForCsdn]# ls -l test.script 
-rw-r----- 1 root root 0 Nov  1 22:43 test.script
[root@localhost testForCsdn]# chmod 744 test.script 
[root@localhost testForCsdn]# ls -l test.script 
-rwxr--r-- 1 root root 0 Nov  1 22:43 test.script

二、chown
改变所有者
首先添加用户hwc
[root@localhost testForCsdn]# useradd hwc
[root@localhost testForCsdn]# chown hwc test.script 
[root@localhost testForCsdn]# ls -l test.script 
-rwxr--r-- 1 hwc root 0 Nov  1 22:43 test.script

三、chgrp
改变所属组
首先添加用户组hwcgroup
[root@localhost testForCsdn]# chgrp hwcgroup test.script 
[root@localhost testForCsdn]# ls -l test.script 
-rwxr--r-- 1 hwc hwcgroup 0 Nov  1 22:43 test.script

四、umask
文件和目录创建的默认权限
查看默认权限
[root@localhost ~]# umask
0022
解释下,这里的第一个0是特殊权限位,一般不作考虑
022是用户权限位,这里的是掩码值
对于文件
即实际的权限应该是完整的权限777-022-111 = 644
就是rw-r--r--
改变缺省的权限值
[root@localhost ~]# umask 027
[root@localhost ~]# umask
0027


  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值