linux chmod 命令

功能

变更文件或目录的权限

语法

chmod [选项] 模式 文件

选项

-c,--changes  权限发生改变时,报告处理信息
-R,--recursive  递归处理
-v,--verbose  显示指令执行的信息

权限

u  拥有者
g  所属群组
o  其他用户
a  全部用户
r  读取权限,数值代码 4
w  写入权限,数值代码 2
x  执行权限,数值代码 1
-  不具有任何权限,数值代码 0

示例

chmod a+x txt对所有用户开放执行权限

lychie@ubuntu:/test$ ls -l
总用量 4
drwxrwxr-x 2 lychie lychie 4096  9月 25 07:30 dir
-rw-r--r-- 1 lychie lychie    0  9月 25 07:18 txt
lychie@ubuntu:/test$ chmod a+x txt
lychie@ubuntu:/test$ ls -l
总用量 4
drwxrwxr-x 2 lychie lychie 4096  9月 25 07:30 dir
-rwxr-xr-x 1 lychie lychie    0  9月 25 07:18 txt
-rwxr-xr-x 1 lychie lychie   0  9月 25 07:18 txt
第一列总共有 10 个字符。第一个字符代表类型,"-" 表明是一个文件,"d" 表明是一个目录;
此后,剩下的 9 个字符中,每 3 个字符一组,依次表示 u,g,o 对此文件或目录的操作权限。

chmod u+x,o+r txt为自己增加执行权限,其他用户增加读取权限

lychie@ubuntu:/test$ ls -l
总用量 4
-rw-r----- 1 lychie lychie 13  9月 25 07:54 txt
lychie@ubuntu:/test$ chmod u+x,o+r txt
lychie@ubuntu:/test$ ls -l
总用量 4
-rwxr--r-- 1 lychie lychie 13  9月 25 07:54 txt

chmod u-x txt删除自己的执行权限

lychie@ubuntu:/test$ ls -l
总用量 4
-rwxr--r-- 1 lychie lychie 13  9月 25 07:54 txt
lychie@ubuntu:/test$ chmod u-x txt
lychie@ubuntu:/test$ ls -l
总用量 4
-rw-r--r-- 1 lychie lychie 13  9月 25 07:54 txt

chmod ug+x txt对自己和群组增加执行权限

lychie@ubuntu:/test$ ls -l
总用量 4
-rw-r--r-- 1 lychie lychie 13  9月 25 07:54 txt
lychie@ubuntu:/test$ chmod ug+x txt
lychie@ubuntu:/test$ ls -l
总用量 4
-rwxr-xr-- 1 lychie lychie 13  9月 25 07:54 txt

chmod u=rw,g=r,o=r txt设置权限

lychie@ubuntu:/test$ ls -l
总用量 4
-rwxr-xr-- 1 lychie lychie 13  9月 25 07:54 txt
lychie@ubuntu:/test$ chmod u=rw,g=r,o=r txt
lychie@ubuntu:/test$ ls -l
总用量 4
-rw-r--r-- 1 lychie lychie 13  9月 25 07:54 txt

chmod 764 txt变更权限

lychie@ubuntu:/test$ ls -l
总用量 4
-rw-r--r-- 1 lychie lychie 13  9月 25 07:54 txt
lychie@ubuntu:/test$ chmod 764 txt
lychie@ubuntu:/test$ ls -l
总用量 4
-rwxrw-r-- 1 lychie lychie 13  9月 25 07:54 txt

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值