CentOS chmod修改文件权限命令

  CentOS使用chmod修改权限。首先CentOS系统默认的文件权限:
-rw-rw-r--    1 user user     150 Mar 19 08:08 foo.txt 

  如果你是文件的拥有者或超级管理员,你才可以设置其他的用户、组或其他用户的访问权限。拥有者和其组有读和写的权限,其他的只有读的权限。如果你想所有人都有写的权限,你可以这样设置:

chmod o+w foo.txt
  o+w告诉系统其他用户和组都有写的权限,结果是:

 -rw-rw-rw-    1 user user     150 Mar 19 08:08 foo.txt 
  如果你不想其他用户有读写的权限,你可以这样设置:

chmod go-rw foo.txt
  go-rw告诉系统其他用户和组都没有读写的权限。

  下面介绍一些相关的名词:

Identities

    u — the user who owns the file (that is, the owner)

    g — the group to which the user belongs

    o — others (not the owner or the owner's group)

    a — everyone or all (u, g, and o) 
Permissions

    r — read access

    w — write access

    x — execute access 
Actions

    + — adds the permission

    - — removes the permission

    = — makes it the only permission 
  测试移除所有权限:

chmod a-rwx foo.txt
  然后用命令 cat foo.txt读取文件结果:

cat: foo.txt: Permission denied
  移除所有权限之后,你仍然要读取文件怎么办,你可以用拥有该文件的用户用下面命令恢复权限:

chmod u+rw foo.txt
  下面列出一些常用的命令:

    g+w — adds write access for the group

    o-rwx — removes all permissions for others

    u+x — allows the file owner to execute the file

    a+rw — allows everyone to read and write to the file

    ug+r — allows the owner and group to read the file

    g=rx — allows only the group to read and execute (not write) 






  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值