chmod 中文man页面

系统
使用chmod命令改变指定文件访问权限有两种方式:一种是用符号标记所进行更改,另一种方式是采用8进制数指定新的访问权限。使用下面的语法格式来使用符号改变方式

命令名

chmod - 改变文件的访问权限  

总揽

chmod [options] mode file...

POSIX 选项:

[-R]

GNU 选项 (最短方式): [-cfvR] [--reference=rfile] [--help] [--version] [--]  

描述

使用chmod命令改变指定文件访问权限有两种方式:一种是用符号标记所进行更改,另一种方式是采用8进制数指定新的访问权限。使用下面的语法格式来使用符号改变方式
`[ugoa...][[+-=][rwxXstugo...]...][,...]'.

在这种格式下,所带参数是一个用逗号分隔的字符列表.每个符号方式的改变命令以零或者字'ugoa'开始;'ugoa'控制哪些用户对该文件访问权限将被改变:文件的所有者(u),与文件所有者同组的用户(g),其他组的用户(o),所有用户(a).因此,a在这里等同于ugo.如果没有带参数,则缺省设置为a,运行效果相同,但是在umask中设置的位将不会受影响.

操作符'+'使得用户选择的权限被追加到每个指定文件,(操作给指定文件添加所选权限);操作符'-'使得这些权限被撤消;'='使得指定文件只具有这些权限。

字符串'rwxXstugo' 给用户选择新的属性:(r)读权限、(w)写权限、 (x)执行权(或对目录的访问权),(X)只有目标文件对某些用户是可执行的或该目标文件是目录时才追加x属性,(s)同时设定用户或组ID,(t)粘滞位(保存程序的文本到交换设备上),(u)目标文件属主,(g)目标文件属主所在的组,(o)其他用户。(因此,'chmod g-s file' 撤消sgid位,'chmod ug+s file'同时设置了suid和sgid位,'chmod o+s file' 则没有进行任何设置)

POSIX并没有粘滞位的描述。它最初是指在交换设备上保留程序文本。现在,如果设置了目录的粘滞位,那么只有文件和目录的所有者可以删除该目录下的文件。 (一般使用于类似于/tmp这样有基本写权限的目录)

数字模式是一到4个八进制数,每个数由位权为4,2,1的3位叠加而得. 被省略掉的数字缺省设置为零. 第一位为4时为suid,2时为sgid,1时为粘滞位,.第二位设置文件所有者的权限:可读(4),可写(2),可执行(1); 第三位设置了文件所在组其他用户的权限,值如上;第四位设置了其他组的用户的权限,值同上.

由于chmod的系统调用不支持,chomd命令不能改变符号链接的权限. 由于符号链接的权限从不使用,所以这也不成问题.无论如何,由于每个符号连接都可在命令行中列出,chmod改变了所指文件的属性. 相反,chmod在递归目录遍历时忽略所碰到的符号连接.  

POSIX 选项

-R 改变目录及目录下的内容的访问权限.  

GNU 选项

-c, --changes
只有在文件的权限确实改变时才进行详细的说明
-f, --silent, --quiet
不输出权限不能改变的文件的错误信息
-v, --verbose
详细说明权限的变化
-R, --recursive
改变目录及其所有子目录的文件的权限
--reference=rfile
(更新在fileutils 4.0上) 改变文件的模式到rfile.

GNU 标准选项

--help
在标准输出上输出帮助信息并退出
--version
在标准输出上输出版本信息并退出
--
终端选项列表

环境变量

变量LANG, LC_ALL, LC_CTYPE ,LC_MESSAGES与一般情况相同. 

遵循

POSIX 1003.2 只需要-R参数。使用其他选项可能无法移植。该标准没有描述 来保持一致性,也就是说,当所有的可执行位都被清除了以后, chomd 是否还完全保留`s'位. 

非标准模式

在上面的内容中我们讨论了't'位在目录上的用法。不同的系统对这些位的组合有特殊的定义。特别是Linux,继System V之后(参考System V 接口描述(SVID)第三卷),给一个文件设置 sgid 位但又不给它设置组执行权限,那么就标志该文件被强制锁住.详细内容,参照文件 /usr/src/linux/Docu-mentation/mandatory.txt  

注意

此页描述的chmod基于fileutils-4.0 package;其他版本可能会有细微的差别.请将修正和增加发送到aeb@cwi.nl. 程序中的错误报告到fileutils-bugs@gnu.ai.mit.edu.  

#p#

NAME

chmod - change file access permissions  

SYNOPSIS

chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...  

DESCRIPTION

This manual page documents the GNU version of chmod. chmod changes the permissions 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 permissions.

The format of a symbolic mode is `[ugoa...][[+-=][rwxXstugo...]...][,...]'. Multiple symbolic operations can be given, separated 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 permissions selected to be added to the existing permissions of each file; `-' causes them to be removed; and `=' causes them to be the only permissions that the file has.

The letters `rwxXstugo' select the new permissions for the affected users: read (r), write (w), execute (or access for directories) (x), execute only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), sticky (t), 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. Any omitted digits are assumed to be leading zeros. The first digit selects the set user ID (4) and set group ID (2) and 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 symbolic link listed on the command line, chmod changes the permissions of the pointed-to file. In contrast, chmod ignores symbolic links encountered during recursive directory traversals.  

STICKY FILES

On older Unix systems, the sticky bit caused executable files to be hoarded in swap space. This feature is not useful on modern VM systems, and the Linux kernel ignores the sticky bit on files. Other kernels may use the sticky bit on files for system-defined purposes. On some systems, only the superuser can set the sticky bit on files.  

STICKY DIRECTORIES

When the sticky bit is set on a directory, files in that directory may be unlinked or renamed only by root or their owner. Without the sticky bit, anyone able to write to the directory can delete or rename files. The sticky bit is commonly found on directories, such as /tmp, that are world-writable.  

OPTIONS

Change the mode of each FILE to MODE.

-c, --changes
like verbose but report only when a change is made
--no-preserve-root
do not treat `/' specially (the default)
--preserve-root
fail to operate recursively on `/'
-f, --silent, --quiet
suppress most error messages
-v, --verbose
output a diagnostic for every file processed
--reference=RFILE
use RFILE's mode instead of MODE values
-R, --recursive
change files and directories recursively
--help
display this help and exit
--version
output version information and exit

Each MODE is one or more of the letters ugoa, one of the symbols +-= and one or more of the letters rwxXstugo.  

AUTHOR

Written by David MacKenzie and Jim Meyering.  

REPORTING BUGS

Report bugs to <bug-coreutils@gnu.org>.  

COPYRIGHT

Copyright © 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

SEE ALSO

The full documentation for chmod is maintained as a Texinfo manual. If the info and chmod programs are properly installed at your site, the command

info coreutils chmod

should give you access to the complete manual.

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-25 15:39:42

fcloseall中文man

2011-08-25 15:00:15

cfgetispeed中文man

2011-08-19 18:35:50

issue中文man

2011-08-25 17:03:51

pclose中文man

2011-08-25 17:40:25

setvbuf中文man

2011-08-23 14:21:16

poweroff中文man

2011-08-24 15:52:59

intro中文man

2011-08-23 13:40:31

2011-08-25 15:54:08

ferror中文man

2011-08-25 17:24:54

puts中文man

2011-08-25 18:34:55

ungetc中文man

2011-08-23 10:03:40

useradd中文man

2011-08-23 10:29:02

chpasswd中文man

2011-08-23 10:34:22

convertquot中文man

2011-08-23 15:39:34

rpmbuild中文man

2011-08-24 15:48:38

INSERT中文man
点赞
收藏

51CTO技术栈公众号