Skip to content

Instantly share code, notes, and snippets.

@lanrion
Created March 9, 2016 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lanrion/4722c09c58665d7bbd47 to your computer and use it in GitHub Desktop.
Save lanrion/4722c09c58665d7bbd47 to your computer and use it in GitHub Desktop.
chmod 理解
作为选择,我们多数用三位八进制数字的形式来表示权限,第一位指定属主的权限,第二位指定组权限,第三位指定其他用户的权限,每位通过4(读)、2(写)、1(执行)三种数值的和来确定权限。如6(4+2)代表有读写权,7(4+2+1)有读、写和执行的权限。
还可设置第四位,它位于三位权限序列的前面,第四位数字取值是4,2,1,代表意思如下:
4,执行时设置用户ID,用于授权给基于文件属主的进程,而不是给创建此进程的用户。
2,执行时设置用户组ID,用于授权给基于文件所在组的进程,而不是基于创建此进程的用户。
1,设置粘着位。
实例:
$ chmod u+x file     给file的属主增加执行权限
$ chmod 751 file     给file的属主分配读、写、执行(7)的权限,给file的所在组分配读、执行(5)的权限,给其他用户分配执行(1)的权限
$ chmod u=rwx,g=rx,o=x file 上例的另一种形式
$ chmod =r file     为所有用户分配读权限
$ chmod 444 file      同上例
$ chmod a-wx,a+r file      同上例
$ chmod -R u+r directory   递归地给directory目录下所有文件和子目录的属主分配读的权限
$ chmod 4755   设置用ID,给属主分配读、写和执行权限,给组和其他用户分配读、执行的权限。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment