CHMOD(1) General Commands Manual CHMOD(1)

chmodChange files modes

chmod [-cRv] mode file...

chmod [-cRv] -F ref_file file...

chmod sets the permissions bits given by mode or copying permissions from ref_file on each given file,

mode can be either an octal natural number between 0 and 7777, or a symbolic operation like ‘+r’ or ‘g=o-x’. See the OCTAL MODE and SYMBOLIC OPERATIONS sections for details.

If mode starts with a dash (or is user-provided), it should be broken from options with a preceding double-dash (--) like so:

chmod -v -- -w,+r foobar

Print mode changes
ref_file
Copy permission bits from ref_file into each file.
Recurse into directories passed to
Verbose, print both changes and retained modes file

Octal natural number between 0 and 7777, which can be obtained by or'ing the following values:

4000
setuid
2000
setgid
1000
sticky bit
0400
user read
0200
user write
0100
user execute/search
0070
group read, write, execute/search
0007
others read, write, execute/search

Uses the following grammar:

mode   ::= clause [',' clause]*
clause ::= who* action+
action ::= [op | op perm+ | op permcopy]

who  ::= 'u' | 'g' | 'o' | 'a'
op   ::= '+' | '-' | '='
perm ::= 'r' | 'w' | 'x' | 'X' | 's' | 't'

permcopy ::= 'u' | 'g' | 'o'

Which corresponds to:

mode
List of ‘clause’ to apply, each separated by a comma.

For example ‘g+r,o=g’ sets read permission for group part and copies to other part the resulting permissions of the group part.

clause
Optionally starts with ‘who’ and contains one or more ‘action’.

When ‘who’ isn't given, umask(3) is followed similarly to file creation.

action
Always starts with ‘op’, optionally followed by either one or more ‘perm’, or a single ‘permcopy
who
user(u), group(g), other(o), all(a)
op
Operation to apply: add(+), del(-), set(=)

When neither ‘perm’ nor ‘permcopy’ were given, set(=) clears all permissions.

perm
which permissions to assign:
r
Read
w
Write
x
Execute/Search
X
Search (directories-only)
s
Setuid when assigned to user, setgid when assigned to group
t
Sticky bit
permcopy
who to copy permissions from: user(u), group(g), other(o)

The chmod utility exits 0 on success, and >0 if an error occurs.

stat(1)

chmod should be compliant with the IEEE Std 1003.1-2024 (“POSIX.1”) specification.

The -c and -v options are present for compatibility with other modern systems such as BusyBox and GNU coreutils. Similarly the -F option was created for compatibility with --reference from GNU, BusyBox and NetBSD while keeping the possibility of using short options.

Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>

2024-03-12 Linux 6.6.67-gentoo-x86_64