详细讲解Linux 命令 chmod

   2017-01-06 0
核心提示:本文是在man命令的基础上进行讲解的,如果不懂man 命令可以跳转http://blog.csdn.net/qq_16877261/article/details/53857594。chmod - change file mode bits 我理解的就是改变文件或目录的权限下面我就可以边翻译man命令,边进行chmod命令的演示。下面主要对

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

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

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

详细讲解Linux 命令 chmod

详细讲解Linux 命令 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忽略遇到的软连接。

 
标签: Linux命令
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • 每天一条linux命令——halt
    halt命令用来关闭正在运行的Linux操作系统。halt命令会先检测系统的runlevel,若runlevel为0或6,则关闭系统,否则即调用shutdown来关闭系统。 语法:halt(选项)选项:-d:不要在wtmp中记录;-f:不论目前的runlevel为何,不调用shutdown即强制关闭系统;-i:
    02-10
  • 几个linux命令查看堆栈内存问题 几个linux命令
      公司编写代码,发现整个在程序里面调用system时候总是失败,原因是can't allocate memory ,根本原因不是内存不足,而是堆栈内存不够。使用ulimit -s 2048后有所好转但是发现一旦系统进程开启多了后仍然会挂。后来使用objdump -x 后发现了原因有个动态库
    02-09
  • Linux命令总结--rm命令 linux的rmp命令
    (来源于http://www.cnblogs.com/xqzt/p/5398919.html)1、命令简介rm(Remove file 删除目录或文件)删除文件,对于链接文件,只是删除整个链接文件,而原有文件保持不变。新手在删除文件之前一定要知道这些:很重要1.可以用mv代替rm的绝对不要用rm,不要着急
    02-09
  • Linux命令行批量创建目录详解 linux创建目录
    以前一直用-p创建目录链,觉得很方便了。在空目录/opt/app/myapp里创建src,再创建main,再创建javamkdir -p /opt/app/myapp/src/main/java没想到还可以这样玩##¥%……*(root@vm1:~/tmp# mkdir -p src/{{main,test}/{java,resources},main/webapp}root@vm1:
    02-09
  • Linux命令之乐--script和scriptplay
    script和scriptplay可以把终端会话记录到一个文件中,可以用来制作命令行教学视屏。 开始录制会话[root@new test]# script -t 2timing.log -a output.sessionScript started, file is output.session[root@new test]# echo hellohello[root@new test]# echo
    02-09
  • java 开发常用的Linux命令
    1.查找文件 find / -name filename.txt 根据名称查找/目录下的filename.txt文件。find . -name "*.xml" 递归查找所有的xml文件find . -name "*.xml" |xargs grep "hello world" 递归查找所有文件内容中包含hello world的xml文件grep -H 'spring' *.xml 查找所
    02-09
  • 常用Linux命令整理 Linux常用命令总结
    常用Linux命令整理常见系统命令export 查看或修改环境变量# 例:临时修改命令提示符为字符串$export PS1=$# 例:临时修改命令提示符显示系统时间 时间使用\t 表示export PS1="[\u@\h \t \W]\$"man 查看linux系统的手册# 例:查看ls命令如何使用man ls # 回车
    02-09 Linux
  • linux命令行—《命令行快速入门》 linux常用命令csdn
    linux命令行—《命令行快速入门》 linux常用命
    pwd print working directory 打印工作目录hostname my computer's network name 电脑在网络中的名称mkdir make directory 创建路径cd change directory 改变路径ls list directory 列出路径下的内容rmdir remove directory 删除路径pushd push directory 推
    02-09
  • Linux命令(五) 五个常用的linux命令
    Linux命令(五) 五个常用的linux命令
    jenkins触发钉钉报警机制1、安装钉钉插件钉钉报警需要安装Ding Talk插件,支持钉钉报警2、打开钉钉创建钉钉机器人2.1选择机器人类型——自定义2.2添加机器人2.3填写机器人信息填写机器人姓名—设置安全设置为加密类型,并复制出来加密值2.4创建完成保持webhoo
    02-09
  • 03_Linux基础-文件类型-主辅提示符-第1提示符-Linux命令-内外部命令-快捷键-改为英文编码-3个时间-stat-其他基础命令
    03_Linux基础-文件类型-主辅提示符-第1提示符-L
    03_Linux基础-文件类型-主辅提示符-第1提示符-Linux命令-内外部命令-快捷键-改为英文编码-3个时间-stat-{1..100}-du-cd-cp-file-mv-echo-id-shell-ln-env-set-which-rpm-/usr-/与/root-hostname-vim-cat-pwd-alias-unalias-ls-ASCII-wc-chmod博客
    02-09
点击排行