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) 






你可能感兴趣的:(centos)