logo

utils-std

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

chmod.1 (3248B)


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