logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

chmod.1 (3258B)


  1. .\" utils-std: Collection of commonly available Unix tools
  2. .\" Copyright 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. .\" SPDX-License-Identifier: MPL-2.0
  4. .Dd April 6, 2025
  5. .Dt CHMOD 1
  6. .Os
  7. .Sh NAME
  8. .Nm chmod
  9. .Nd Change files modes
  10. .Sh SYNOPSIS
  11. .Nm
  12. .Op Fl cRv
  13. .Ar mode
  14. .Ar file...
  15. .Nm
  16. .Op Fl cRv
  17. .Fl -reference Ar ref_file
  18. .Ar file...
  19. .Sh DESCRIPTION
  20. .Nm
  21. sets the permissions bits given by
  22. .Ar mode
  23. or copying permissions from
  24. .Ar ref_file
  25. on each given
  26. .Ar file ,
  27. .Pp
  28. .Ar mode
  29. can be either an octal natural number between 0 and 7777,
  30. or a symbolic operation like
  31. .Ql +r
  32. or
  33. .Ql g=o-x .
  34. See the
  35. .Sx OCTAL MODE
  36. and
  37. .Sx SYMBOLIC OPERATIONS
  38. sections for details.
  39. .Pp
  40. If
  41. .Ar mode
  42. starts with a dash (or is user-provided),
  43. it should be broken from options with a preceding double-dash
  44. .Pq --
  45. like so:
  46. .Dl chmod -v -- -w,+r foobar
  47. .Sh OPTIONS
  48. .Bl -tag -width Ds
  49. .It Fl c
  50. Print mode changes
  51. .It Fl -reference Ar ref_file
  52. Copy permission bits from
  53. .Ar ref_file
  54. into each
  55. .Ar file .
  56. .It Fl R
  57. Recurse into directories passed to
  58. .It Fl v
  59. Verbose, print both changes and retained modes
  60. .Ar file
  61. .El
  62. .Sh OCTAL MODE
  63. Octal natural number between 0 and 7777,
  64. which can be obtained by or'ing the following values:
  65. .br
  66. .Bl -tag -width 0000 -compact
  67. .It 4000
  68. setuid
  69. .It 2000
  70. setgid
  71. .It 1000
  72. sticky bit
  73. .It 0400
  74. user read
  75. .It 0200
  76. user write
  77. .It 0100
  78. user execute/search
  79. .It 0070
  80. group read, write, execute/search
  81. .It 0007
  82. others read, write, execute/search
  83. .El
  84. .Sh SYMBOLIC OPERATIONS
  85. Uses the following grammar:
  86. .Bd -literal
  87. mode ::= clause [',' clause]*
  88. clause ::= who* action+
  89. action ::= [op | op perm+ | op permcopy]
  90. who ::= 'u' | 'g' | 'o' | 'a'
  91. op ::= '+' | '-' | '='
  92. perm ::= 'r' | 'w' | 'x' | 'X' | 's' | 't'
  93. permcopy ::= 'u' | 'g' | 'o'
  94. .Ed
  95. .Pp
  96. Which corresponds to:
  97. .Bl -tag -width permcopy
  98. .It mode
  99. List of
  100. .Ql clause
  101. to apply, each separated by a comma.
  102. .Pp
  103. For example
  104. .Ql g+r,o=g
  105. sets read permission for group part and
  106. copies to other part the resulting permissions of the group part.
  107. .It clause
  108. Optionally starts with
  109. .Ql who
  110. and contains one or more
  111. .Ql action .
  112. .Pp
  113. When
  114. .Ql who
  115. isn't given,
  116. .Xr umask 3
  117. is followed similarly to file creation.
  118. .It action
  119. Always starts with
  120. .Ql op ,
  121. optionally followed by either one or more
  122. .Ql perm ,
  123. or a single
  124. .Ql permcopy
  125. .It who
  126. user(u), group(g), other(o), all(a)
  127. .It op
  128. Operation to apply: add(+), del(-), set(=)
  129. .Pp
  130. When neither
  131. .Ql perm
  132. nor
  133. .Ql permcopy
  134. were given, set(=) clears all permissions.
  135. .It perm
  136. which permissions to assign:
  137. .Bl -tag -width X -compact
  138. .It r
  139. Read
  140. .It w
  141. Write
  142. .It x
  143. Execute/Search
  144. .It X
  145. Search (directories-only)
  146. .It s
  147. Setuid when assigned to user, setgid when assigned to group
  148. .It t
  149. Sticky bit
  150. .El
  151. .It permcopy
  152. who to copy permissions from: user(u), group(g), other(o)
  153. .El
  154. .Sh EXIT STATUS
  155. .Ex -std
  156. .Sh SEE ALSO
  157. .Xr stat 1
  158. .Sh STANDARDS
  159. .Nm
  160. should be compliant with the
  161. IEEE Std 1003.1-2024 (“POSIX.1”)
  162. specification.
  163. .Pp
  164. The
  165. .Fl c ,
  166. .Fl v
  167. and
  168. .Fl -reference
  169. options are present for compatibility with other modern systems such as
  170. BusyBox and GNU coreutils.
  171. .Sh HISTORY
  172. The
  173. .Fl c
  174. and
  175. .Fl v
  176. options were present in utils-std 0.0.1.
  177. The
  178. .Fl -reference
  179. option was added in utils-std 0.0.2.
  180. .Sh AUTHORS
  181. .An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me