详细讲解Linux 命令 chmod

本文是在man命令的基础上进行讲解的,如果不懂man 命令可以跳转http://blog.csdn.net/qq_16877261/article/details/53857594。

   chmod - change file mode bits  我理解的就是改变文件或目录的权限

下面我就可以边翻译man命令,边进行chmod命令的演示。



下面主要对描述进行翻译,没翻译的就是我不会翻译。

This manual page documents the GNU version of chmod.  chmod changes the file mode bits of each given file  according  to  mode,  which  can  be either a symbolic representation of changes to make, or an octal number representing the bit pattern for the new mode bits.

The format of a symbolic mode is  [ugoa...][[-+=][perms...]...],  where perms  is  either zero or more letters from the set rwxXst, or a single letter from the set ugo.  Multiple symbolic modes can be  given,  sepa-rated by commas.

 A  combination  of the letters ugoa controls which users' access to the   file will be changed: the user who owns it  (u),  other  users  in  the file's group (g), other users not in the file's group (o), or all users (a).  If none of these are given, the effect is as if (a)  were  given, but bits that are set in the umask are not affected.

  The  operator  +  causes the selected file mode bits to be added to the  existing file mode bits of each file; - causes them to be removed;  and  =  causes  them  to  be added and causes unmentioned bits to be removed  except that a directory's unmentioned set user and group  ID  bits  are not affected.

 The  letters  rwxXst select file mode bits for the affected users: read  (r), write (w), execute (or search for directories) (x), execute/search only  if  the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), restricted  dele- tion  flag or sticky bit (t).  Instead of one or more of these letters,
 you can specify exactly one of the letters ugo: the permissions granted to  the  user  who  owns the file (u), the permissions granted to other users who are members of the file's  group  (g),  and  the  permissions granted  to  users  that are in neither of the two preceding categories (o).

 A numeric mode is from one to  four  octal  digits  (0-7),  derived  by  adding up the bits with values 4, 2, and 1.  Omitted digits are assumed  to be leading zeros.  The first digit selects the set user ID  (4)  and  set group ID (2) and restricted deletion or sticky (1) attributes.  The second digit selects permissions for the user who owns the  file:  read(4),  write  (2),  and  execute  (1); the third selects permissions for other users in the file's group, with the same values; and  the  fourth for other users not in the file's group, with the same values.

chmod never changes the permissions of symbolic links; the chmod system  call cannot change their permissions.  This is not a problem since  the  permissions  of  symbolic links are never used.  However, for each sym‐bolic link listed on the command line, chmod changes the permissions of  the pointed-to file.  In contrast, chmod ignores symbolic links encoun‐ tered during recursive directory traversals.

chmod 命令可以根据模式(mode) 改变给定文件的的模式位,mode 既可以是一个所做改变的符号代表,也可以是一个八进制的代表位形式的模式位。

  chmod   u=rwx  test   或者 chmod   0777  test

符号模式的形式是 [ugoa...][[-+=][perms...]...], perms 既可以是0或者是集合 rwxXst里的多个字母,或者来自于集合ugo中的一个字母。多个符号模式可以通过逗号分隔来设置。

ugoa的字母集合控制着哪一个用户对文件的权限将被改变:拥有这个文件的用户(U),这个文件所属用户组的其他用户(g),不在这个文件所属用户组的其他用户(o),或者所有用户(a)。如果这些都没有,事实上默认为a,即所有用户,但是在权限掩码中设置的位不受影响。

操作符+号在现有的文件模式位上添加文件模式位,-号移除文件模式位,并且=号添加文件模式位并且将未提到的文件模式位移除,然而一个目录的未提及的固定的用户和用户组ID不受影响。

对于受影响的用户字母 rwxXst 选择文件模式位:读(r),写(w),执行(或者搜索目录)(x),执行/仅在文件是一个目录或者对某个用户已经有执行权限下搜索,设置用户或用户组ID可执行(s),受限的删除标识或者粘性位(t),除了可以指明一个或多个字母外,你也可以指明ugo字母中的一个:授予拥有这个文件用户的所有权限,授予这个文件所属用户组的权限,和不在上述两种类别的用户 的权限。

一个数字位是由1到4个八进制数字的值4、2和1相加产生的。遗漏的数字被认为结果为0。第一个数字选择设置好的用户ID(4)和设置好的用户组ID(2),和受限的删除或者粘滞属性。第二个数字选择文件所属用户的权限:读(4),写(2),和执行(1);第三个选择其他文件所属用户组的其他用户的权限,第四个选择不在这个文件用户组的其他用户的权限。

chmod命令从来不会改变软连接的权限;chmod命令系统要求不能改变他们的权限。只要软连接的权限从不使用,这就不是问题。然而,对于每一个在命令行显示的软连接,chmod 改变软连接指向的文件的权限。相比之下,在进行递归目录的遍历时,chmod忽略遇到的软连接。


读书生活,请关注下面的公众号











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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值