You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

chmod.html 8.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Chmod Task</title>
  20. </head>
  21. <body>
  22. <h2 id="chmod">Chmod</h2>
  23. <h3>Description</h3>
  24. <p>Changes the permissions of a file or all files inside specified directories. Right now it has
  25. effect only under Unix or NonStop Kernel (Tandem). The permissions are also UNIX style, like the
  26. argument for the <kbd>chmod</kbd> command.</p>
  27. <p>See the section on <a href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on
  28. how the inclusion/exclusion of files works, and how to write patterns.</p>
  29. <p>This task holds an implicit <a href="../Types/fileset.html">FileSet</a> and supports all of
  30. FileSet's attributes and nested elements directly. More sets can be specified using
  31. nested <code>&lt;fileset&gt;</code> or <code>&lt;dirset&gt;</code> (<em>since Apache Ant 1.6</em>)
  32. elements.</p>
  33. <p><em>Since Ant 1.6</em>, this task also supports
  34. nested <a href="../Types/filelist.html">filelist</a>s.</p>
  35. <p><em>Since Ant 1.7</em>, this task supports
  36. arbitrary <a href="../Types/resources.html#collection">resource collections</a> as nested
  37. elements.</p>
  38. <p>By default this task will use a single invocation of the underlying <kbd>chmod</kbd> command.
  39. If you are working on a large number of files this may result in a command line that is too long for
  40. your operating system. If you encounter such problems, you should set the <var>maxparallel</var>
  41. attribute of this task to a non-zero value. The number to use highly depends on the length of your
  42. file names (the depth of your directory tree) and your operating system, so you'll have to
  43. experiment a little. POSIX recommends command line length limits of at least 4096 characters, this
  44. may give you an approximation for the number you could use as initial value for these
  45. experiments.</p>
  46. <p>By default this task won't do anything unless it detects it is running on a Unix system. If you
  47. know for sure that you have a <kbd>chmod</kbd> executable on your <code>PATH</code> that is
  48. command line compatible with the Unix command, you can use the task's <var>os</var> attribute and
  49. set its value to your current OS.</p>
  50. <p>See the <a href="setpermissions.html">setpermissions</a> task for a platform independent
  51. alternative.</p>
  52. <h3>Parameters</h3>
  53. <table class="attr">
  54. <tr>
  55. <th scope="col">Attribute</th>
  56. <th scope="col">Description</th>
  57. <th scope="col">Required</th>
  58. </tr>
  59. <tr>
  60. <td>file</td>
  61. <td>the file or single directory of which the permissions must be changed.</td>
  62. <td rowspan="2">Exactly one of the two, unless
  63. nested <code>&lt;fileset|filelist|dirset&gt;</code> elements are specified</td>
  64. </tr>
  65. <tr>
  66. <td>dir</td>
  67. <td class="left">the directory which holds the files whose permissions must be
  68. changed.<br/><strong>Note</strong>: for backwards compatibility reasons <code>&lt;chmod
  69. dir="some-dir"/&gt;</code> will only change the permissions on <samp>some-dir</samp> but not
  70. recurse into it, unless you also specify any patterns.</td>
  71. </tr>
  72. <tr>
  73. <td>perm</td>
  74. <td>the new permissions.</td>
  75. <td>Yes</td>
  76. </tr>
  77. <tr>
  78. <td>includes</td>
  79. <td>comma- or space-separated list of patterns of files that must be included.</td>
  80. <td>No; defaults to all (<q>**</q>)</td>
  81. </tr>
  82. <tr>
  83. <td>excludes</td>
  84. <td>comma- or space-separated list of patterns of files that must be excluded.</td>
  85. <td>No; defaults to default excludes or none if <var>defaultexcludes</var> is <q>no</q></td>
  86. </tr>
  87. <tr>
  88. <td>defaultexcludes</td>
  89. <td>indicates whether default excludes should be used or not (<q>yes|no</q>).</td>
  90. <td>No; defaults to <q>yes</q></td>
  91. </tr>
  92. <tr>
  93. <td>parallel</td>
  94. <td>process all specified files using a single <kbd>chmod</kbd> command.</td>
  95. <td>No; defaults to <q>true</q></td>
  96. </tr>
  97. <tr>
  98. <td>type</td>
  99. <td>One of <q>file</q>, <q>dir</q> or <q>both</q>. If set to <q>file</q>, only the permissions
  100. of plain files are going to be changed. If set to <q>dir</q>, only the directories are
  101. considered.<br/><strong>Note</strong>: The type attribute does not apply to
  102. nested <code>dirset</code>s&mdash;<code>dirset</code>s always implicitly assume type to
  103. be <q>dir</q>.</td>
  104. <td>No; default is <q>file</q></td>
  105. </tr>
  106. <tr>
  107. <td>maxparallel</td>
  108. <td>Limit the amount of parallelism by passing at most this many sourcefiles at once. Set it to
  109. negative integer for unlimited. <em>Since Ant 1.6</em>.</td>
  110. <td>No; defaults to unlimited</td>
  111. </tr>
  112. <tr>
  113. <td>verbose</td>
  114. <td>Whether to print a summary after execution or not. <em>Since Ant 1.6</em>.</td>
  115. <td>No; defaults to <q>false</q></td>
  116. </tr>
  117. <tr>
  118. <td>os</td>
  119. <td>list of Operating Systems on which the command may be executed.</td>
  120. <td>No</td>
  121. </tr>
  122. <tr>
  123. <td>osfamily</td>
  124. <td>OS family as used in the <a href="conditions.html#os">&lt;os&gt;</a> condition.</td>
  125. <td>No; defaults to <q>unix</q></td>
  126. </tr>
  127. </table>
  128. <h3>Examples</h3>
  129. <p>Make the <samp>start.sh</samp> file readable and executable for anyone on a UNIX system.</p>
  130. <pre>&lt;chmod file=&quot;${dist}/start.sh&quot; perm=&quot;ugo+rx&quot;/&gt;</pre>
  131. <p>Make the <samp>start.sh</samp> file readable, writable and executable only for the owner on a
  132. UNIX system.</p>
  133. <pre>&lt;chmod file=&quot;${dist}/start.sh&quot; perm=&quot;700&quot;/&gt;</pre>
  134. <p>Make all <samp>.sh</samp> files below <samp>${dist}/bin</samp> readable and executable for anyone
  135. on a UNIX system.</p>
  136. <pre>
  137. &lt;chmod dir=&quot;${dist}/bin&quot; perm=&quot;ugo+rx&quot;
  138. includes=&quot;**/*.sh&quot;/&gt;</pre>
  139. <p>Make all files below <samp>shared/sources1</samp> (except those below any directory
  140. named <samp>trial</samp>) writable for members of the same group on a UNIX system. In addition, all
  141. files belonging to a FileSet with <var>id</var> <samp>other.shared.sources</samp> get the same
  142. permissions.</p>
  143. <pre>
  144. &lt;chmod perm=&quot;g+w&quot;&gt;
  145. &lt;fileset dir=&quot;shared/sources1&quot;&gt;
  146. &lt;exclude name=&quot;**/trial/**&quot;/&gt;
  147. &lt;/fileset&gt;
  148. &lt;fileset refid=&quot;other.shared.sources&quot;/&gt;
  149. &lt;/chmod&gt;</pre>
  150. <p>Keep non-owners from touching <code>cgi</code> scripts, files with a <samp>.old</samp> extension
  151. or directories beginning with <samp>private_</samp>. A directory ending in <samp>.old</samp> or a
  152. file beginning with <samp>private_</samp> would remain unaffected.</p>
  153. <pre>
  154. &lt;chmod perm=&quot;go-rwx&quot; type=&quot;file&quot;&gt;
  155. &lt;fileset dir=&quot;/web&quot;&gt;
  156. &lt;include name=&quot;**/*.cgi&quot;/&gt;
  157. &lt;include name=&quot;**/*.old&quot;/&gt;
  158. &lt;/fileset&gt;
  159. &lt;dirset dir=&quot;/web&quot;&gt;
  160. &lt;include name=&quot;**/private_*&quot;/&gt;
  161. &lt;/dirset&gt;
  162. &lt;/chmod&gt;</pre>
  163. <h3>Note on <var>maxparallel</var> attribute</h3>
  164. <p>Some shells have a limit of the number of characters that a command line may contain. This
  165. maximum limit varies from shell to shell and from operating system to operating system. If one has
  166. a large number of files to change mode on, consider using the <var>maxparallel</var> attribute. For
  167. example when using AIX and the limit is reached, the system responds with a warning: <code>"Warning:
  168. UNIXProcess.forkAndExec native error: The parameter or environment lists are too long"</code>. A
  169. value of about 300 seems to result in a command line that is acceptable.</p>
  170. </body>
  171. </html>