📄 chmod.html
字号:
<td align="left"><p class="tent"><b>0002</b></p></td><td align="left"><p class="tent">S_IWOTH</p></td></tr><tr valign="top"><td align="left"><p class="tent"><b><img src="../images/opt-start.gif" border="0">1000</b></p></td><td align="left"><p class="tent">S_ISVTX<img src="../images/opt-end.gif" border="0"></p></td><td align="left"><p class="tent"><b>0100</b></p></td><td align="left"><p class="tent">S_IXUSR</p></td><td align="left"><p class="tent"><b>0010</b></p></td><td align="left"><p class="tent">S_IXGRP</p></td><td align="left"><p class="tent"><b>0001</b></p></td><td align="left"><p class="tent">S_IXOTH</p></td></tr></table></center><p>When bits are set in the octal number other than those listed in the table above, the behavior is unspecified.</p><h5><a name="tag_04_18_13_01"></a>Grammar for chmod</h5><p>The grammar and lexical conventions in this section describe the syntax for the <i>symbolic_mode</i> operand. The generalconventions for this style of grammar are described in <a href="xcu_chap01.html#tag_01_10"><i>Grammar Conventions</i></a>. A valid<i>symbolic_mode</i> can be represented as the non-terminal symbol <i>symbolic_mode</i> in the grammar. This formal syntax shalltake precedence over the preceding text syntax description.</p><p>The lexical processing is based entirely on single characters. Implementations need not allow <blank>s within the singleargument being processed.</p><pre><tt>%start symbolic_mode%%<br>symbolic_mode : clause | symbolic_mode ',' clause ;<br>clause : actionlist | wholist actionlist ;<br>wholist : who | wholist who ;<br>who : 'u' | 'g' | 'o' | 'a' ;<br>actionlist : action | actionlist action ;<br>action : op | op permlist | op permcopy ;<br>permcopy : 'u' | 'g' | 'o' ;<br>op : '+' | '-' | '=' ;<br>permlist : perm | perm permlist ;<br><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup>perm : 'r' | 'w' | 'x' | 'X' | 's' |<img src="../images/opt-start.gif" border="0"> 't' <img src="../images/opt-end.gif" border="0"> ;</tt></pre></blockquote><h4><a name="tag_04_18_14"></a>EXIT STATUS</h4><blockquote><p>The following exit values shall be returned:</p><dl compact><dt> 0</dt><dd>The utility executed successfully and all requested changes were made.</dd><dt>>0</dt><dd>An error occurred.</dd></dl></blockquote><h4><a name="tag_04_18_15"></a>CONSEQUENCES OF ERRORS</h4><blockquote><p>Default.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_04_18_16"></a>APPLICATION USAGE</h4><blockquote><p>Some implementations of the <i>chmod</i> utility change the mode of a directory before the files in the directory whenperforming a recursive ( <b>-R</b> option) change; others change the directory mode after the files in the directory. If anapplication tries to remove read or search permission for a file hierarchy, the removal attempt fails if the directory is changedfirst; on the other hand, trying to re-enable permissions to a restricted hierarchy fails if directories are changed last. Usersshould not try to make a hierarchy inaccessible to themselves.</p><p>Some implementations of <i>chmod</i> never used the process' <a href="../utilities/umask.html"><i>umask</i></a> when changingmodes; systems conformant with this volume of IEEE Std 1003.1-2001 do so when <b>who</b> is not specified. Note thedifference between:</p><pre><tt>chmod a-w file</tt></pre><p>which removes all write permissions, and:</p><pre><tt>chmod -- -w file</tt></pre><p>which removes write permissions that would be allowed if <b>file</b> was created with the same <a href="../utilities/umask.html"><i>umask</i></a>.</p><p>Conforming applications should never assume that they know how the set-user-ID and set-group-ID bits on directories areinterpreted.</p></blockquote><h4><a name="tag_04_18_17"></a>EXAMPLES</h4><blockquote><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Mode</b></p></th><th align="center"><p class="tent"><b>Results</b></p></th></tr><tr valign="top"><td align="left"><p class="tent"><i>a</i>+=</p></td><td align="left"><p class="tent">Equivalent to <i>a</i>+, <i>a</i>=; clears all file mode bits.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><i>go</i>+-w</p></td><td align="left"><p class="tent">Equivalent to <i>go</i>+, <i>go</i>- <i>w</i>; clears group and other write bits.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><i>g</i>=<i>o</i>-<i>w</i></p></td><td align="left"><p class="tent">Equivalent to <i>g</i>= <i>o</i>, <i>g</i>- <i>w</i>; sets group bit to match other bits and then clears groupwrite bit.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><i>g</i>-<i>r</i>+<i>w</i></p></td><td align="left"><p class="tent">Equivalent to <i>g</i>- <i>r</i>, <i>g</i>+ <i>w</i>; clears group read bit and sets group write bit.</p></td></tr><tr valign="top"><td align="left"><p class="tent"><i>uo</i>=<i>g</i></p></td><td align="left"><p class="tent">Sets owner bits to match group bits and sets other bits to match group bits.</p></td></tr></table></center></blockquote><h4><a name="tag_04_18_18"></a>RATIONALE</h4><blockquote><p>The functionality of <i>chmod</i> is described substantially through references to concepts defined in the System Interfacesvolume of IEEE Std 1003.1-2001. In this way, there is less duplication of effort required for describing the interactionsof permissions. However, the behavior of this utility is not described in terms of the <a href="../functions/chmod.html"><i>chmod</i>()</a> function from the System Interfaces volume of IEEE Std 1003.1-2001 becausethat specification requires certain side effects upon alternate file access control mechanisms that might not be appropriate,depending on the implementation.</p><p>Implementations that support mandatory file and record locking as specified by the 1984 /usr/group standard historically usedthe combination of set-group-ID bit set and group execute bit clear to indicate mandatory locking. This condition is usually set orcleared with the symbolic mode <b>perm</b> symbol <b>l</b> instead of the <b>perm</b> symbols <b>s</b> and <b>x</b> so that themandatory locking mode is not changed without explicit indication that that was what the user intended. Therefore, the details onhow the implementation treats these conditions must be defined in the documentation. This volume of IEEE Std 1003.1-2001does not require mandatory locking (nor does the System Interfaces volume of IEEE Std 1003.1-2001), but does allow it asan extension. However, this volume of IEEE Std 1003.1-2001 does require that the <a href="../utilities/ls.html"><i>ls</i></a> and <i>chmod</i> utilities work consistently in this area. If <a href="../utilities/ls.html"><i>ls</i></a> <b>-l</b> <i>file</i> indicates that the set-group-ID bit is set, <i>chmod</i> <b>g-s</b><i>file</i> must clear it (assuming appropriate privileges exist to change modes).</p><p>The System V and BSD versions use different exit status codes. Some implementations used the exit status as a count of thenumber of errors that occurred; this practice is unworkable since it can overflow the range of valid exit status values. Thisproblem is avoided here by specifying only 0 and >0 as exit values.</p><p>The System Interfaces volume of IEEE Std 1003.1-2001 indicates that implementation-defined restrictions may cause theS_ISUID and S_ISGID bits to be ignored. This volume of IEEE Std 1003.1-2001 allows the <i>chmod</i> utility to choose tomodify these bits before calling <a href="../functions/chmod.html"><i>chmod</i>()</a> (or some function providing equivalentcapabilities) for non-regular files. Among other things, this allows implementations that use the set-user-ID and set-group-ID bitson directories to enable extended features to handle these extensions in an intelligent manner.</p><p>The <b>X</b> <b>perm</b> symbol was adopted from BSD-based systems because it provides commonly desired functionality when doingrecursive ( <b>-R</b> option) modifications. Similar functionality is not provided by the <a href="../utilities/find.html"><i>find</i></a> utility. Historical BSD versions of <i>chmod</i>, however, only supported <b>X</b> with<i>op</i>+; it has been extended in this volume of IEEE Std 1003.1-2001 because it is also useful with <i>op</i>=. (Ithas also been added for <i>op</i>- even though it duplicates <b>x</b>, in this case, because it is intuitive and easier toexplain.)</p><p>The grammar was extended with the <i>permcopy</i> non-terminal to allow historical-practice forms of symbolic modes like<b>o</b>= <b>u</b> <b>-g</b> (that is, set the "other" permissions to the permissions of "owner" minus the permissions of"group").</p></blockquote><h4><a name="tag_04_18_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_18_20"></a>SEE ALSO</h4><blockquote><p><a href="ls.html"><i>ls</i></a>, <a href="umask.html"><i>umask</i></a>, the System Interfaces volume ofIEEE Std 1003.1-2001, <a href="../functions/chmod.html"><i>chmod</i>()</a></p></blockquote><h4><a name="tag_04_18_21"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 2.</p></blockquote><h4><a name="tag_04_18_22"></a>Issue 6</h4><blockquote><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>Octal modes have been kept and made mandatory despite being marked obsolescent in the ISO POSIX-2:1993 standard.</p></li></ul><p>IEEE PASC Interpretation 1003.2 #172 is applied, changing the CONSEQUENCES OF ERRORS section to "Default.".</p><p>The Open Group Base Resolution bwg2001-010 is applied, adding the description of the S_ISVTX bit and the <b>t perm</b>symbol as an XSI extension.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XCU/TC1/D6/16 is applied, changing the XSI shaded text in the EXTENDEDDESCRIPTION from:</p><blockquote>``The <b>perm</b> symbol <b>t</b> shall specify the S_ISVTX bit and shall apply to directories only. The effect whenusing it with any other file type is unspecified. It can be used with the <b>who</b> symbols <b>o</b>, <b>a</b>, or with no<b>who</b> symbol. It shall not be an error to specify a <b>who</b> symbol of <b>u</b> or <b>g</b> in conjunction with the<b>perm</b> symbol <b>t</b>; it shall be ignored for <b>u</b> and <b>g</b>."</blockquote><p>to:</p><blockquote>``The <b>perm</b> symbol <b>t</b> shall specify the S_ISVTX bit. When used with a file of type directory, it can beused with the <b>who</b> symbol <b>a</b>, or with no <b>who</b> symbol. It shall not be an error to specify a <b>who</b> symbol of<b>u</b>, <b>g</b>, or <b>o</b> in conjunction with the <b>perm</b> symbol <b>t</b>, but the meaning of these combinations isunspecified. The effect when using the <b>perm</b> symbol <b>t</b> with any file type other than directory isunspecified."</blockquote><p>This change is to permit historical behavior.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -