xref: /csrg-svn/bin/chmod/chmod.1 (revision 63674)
1*63674Sbostic.\" Copyright (c) 1989, 1990, 1993
2*63674Sbostic.\"	The Regents of the University of California.  All rights reserved.
319384Smckusick.\"
450181Sbostic.\" This code is derived from software contributed to Berkeley by
550181Sbostic.\" the Institute of Electrical and Electronics Engineers, Inc.
650181Sbostic.\"
750492Scael.\" %sccs.include.redist.roff%
839829Sbostic.\"
9*63674Sbostic.\"	@(#)chmod.1	8.1 (Berkeley) 06/29/93
1039829Sbostic.\"
1143082Scael.Dd
1243082Scael.Dt CHMOD 1
1350492Scael.Os
1443082Scael.Sh NAME
1543082Scael.Nm chmod
1647089Scael.Nd change file modes
1743082Scael.Sh SYNOPSIS
1843082Scael.Nm chmod
1953783Selan.Op Fl HRh
2043082Scael.Ar mode
2143082Scael.Ar file ...
2243082Scael.Sh DESCRIPTION
2339829SbosticThe
2443082Scael.Nm chmod
2539829Sbosticutility modifies the file mode bits of the listed files
2639829Sbosticas specified by the
2743082Scael.Ar mode
2839829Sbosticoperand.
2943082Scael.Pp
3039829SbosticThe options are as follows:
3147089Scael.Bl -tag -width Ds
3253783Selan.It Fl H
3353783SelanWhen encountering a symbolic link on the command line, follow it.  All other
3453783Selansymbolic links encountered in the traversal are not followed.
3547089Scael.It Fl R
3639829SbosticTraverse a file hierarchy.
3739829SbosticFor each file that is of type directory,
3843082Scael.Nm chmod
3939829Sbosticchanges the mode of all files in the file hierarchy below it followed
4039829Sbosticby the mode of the directory itself.
4153783Selan.It Fl h
4253783SelanWhen encountering a symbolic link anywhere in the traversal, follow it.
4347089Scael.El
4443082Scael.Pp
4563673SmckusickThe mode of a symbolic link is immutable, so unless the
4653783Selan.Fl h
4753783Selanor
4853783Selan.Fl H
4963673Smckusickflag is set,
5053783Selan.Nm chmod
5153783Selanon a symbolic link is a no-op.
5243082Scael.Pp
5339829SbosticOnly the owner of a file or the super-user is permitted to change
5439829Sbosticthe mode of a file.
5543082Scael.Pp
5639829SbosticThe
5743082Scael.Nm chmod
5839829Sbosticutility exits 0 on success, and >0 if an error occurs.
5943082Scael.Sh MODES
6039829SbosticModes may be absolute or symbolic.
6139829SbosticAn absolute mode is an octal number constructed by
6253783Selan.Ar or-ing
6339829Sbosticthe following values:
6447089Scael.Pp
6547089Scael.Bl -tag -width 6n -compact -offset indent
6647089Scael.It Li 4000
6739829Sbosticset-user-ID-on-execution
6847089Scael.It Li 2000
6939829Sbosticset-group-ID-on-execution
7047089Scael.It Li 1000
7139829Sbosticsticky bit, see chmod(2)
7247089Scael.It Li 0400
7319384Smckusickread by owner
7447089Scael.It Li 0200
7519384Smckusickwrite by owner
7647089Scael.It Li 0100
7739829Sbosticexecute (or search for directories) by owner
7847089Scael.It Li 0070
7939829Sbosticread, write, execute/search by group
8047089Scael.It Li 0007
8139829Sbosticread, write, execute/search by others
8247089Scael.El
8343082Scael.Pp
8439829SbosticThe read, write, and execute/search values for group and others
8539829Sbosticare encoded as described for owner.
8643082Scael.Pp
8739829SbosticThe symbolic mode is described by the following grammar:
8847089Scael.Bd -literal -offset indent
8947089Scaelmode         ::= clause [, clause ...]
9047089Scaelclause       ::= [who ...] [action ...] last_action
9147089Scaelaction       ::= op [perm ...]
9247089Scaellast_action  ::= op [perm ...]
9347089Scaelwho          ::= a | u | g | o
9447089Scaelop           ::= + | \- | =
9563673Smckusickperm         ::= r | s | t | w | x | X
9647089Scael.Ed
9743082Scael.Pp
9839829SbosticThe
9943082Scael.Ar who
10039829Sbosticsymbols ``u'', ``g'', and ``o'' specify the user, group, and other parts
10139829Sbosticof the mode bits, respectively.
10241117SbosticThe
10343082Scael.Ar who
10441117Sbosticsymbol ``a'' is equivalent to ``ugo''.
10543082Scael.Pp
10663673Smckusick.ne 1i
10739829SbosticThe
10843082Scael.Ar perm
10939829Sbosticsymbols represent the portions of the mode bits as follows:
11047089Scael.Pp
11147089Scael.Bl -tag -width Ds -compact -offset indent
11247089Scael.It r
11339829SbosticThe read bits.
11447089Scael.It s
11539829SbosticThe set-user-ID-on-execution and set-group-ID-on-execution bits.
11647089Scael.It t
11741117SbosticThe sticky bit.
11847089Scael.It w
11939829SbosticThe write bits.
12047089Scael.It x
12141117SbosticThe execute/search bits.
12247089Scael.It X
12339829SbosticThe execute/search bits if the file is a directory or any of the
12441117Sbosticexecute/search bits are set in the original (unmodified) mode.
12541117SbosticOperations with the
12643082Scael.Ar perm
12741117Sbosticsymbol ``X'' are only meaningful in conjunction with the
12843082Scael.Ar op
12963673Smckusicksymbol ``+'', and are ignored in all other cases.
13047089Scael.El
13143082Scael.Pp
13239829SbosticThe
13343082Scael.Ar op
13439829Sbosticsymbols represent the operation performed, as follows:
13547089Scael.Bl -tag -width 4n
13647089Scael.It +
13739829SbosticIf no value is supplied for
13843082Scael.Ar perm ,
13939829Sbosticthe ``+'' operation has no effect.
14039829SbosticIf no value is supplied for
14143082Scael.Ar who ,
14239829Sbosticeach permission bit specified in
14343082Scael.Ar perm ,
14441117Sbosticfor which the corresponding bit in the file mode creation mask
14541117Sbosticis clear, is set.
14641117SbosticOtherwise, the mode bits represented by the specified
14743082Scael.Ar who
14839829Sbosticand
14943082Scael.Ar perm
15041117Sbosticvalues are set.
15147089Scael.It \&\-
15239829SbosticIf no value is supplied for
15343082Scael.Ar perm ,
15447089Scaelthe ``\-'' operation has no effect.
15541117SbosticIf no value is supplied for
15643082Scael.Ar who ,
15741117Sbosticthe mode bits represented by
15843082Scael.Ar perm
15941117Sbosticare cleared for the owner, group and other permissions.
16041117SbosticOtherwise, the mode bits represented by the specified
16143082Scael.Ar who
16239829Sbosticand
16343082Scael.Ar perm
16441117Sbosticvalues are cleared.
16547089Scael.It =
16641117SbosticThe mode bits specified by the
16743082Scael.Ar who
16841117Sbosticvalue are cleared, or, if no who value is specified, the owner, group
16941117Sbosticand other mode bits are cleared.
17041117SbosticThen, if no value is supplied for
17143082Scael.Ar who ,
17241117Sbosticeach permission bit specified in
17343082Scael.Ar perm ,
17441117Sbosticfor which the corresponding bit in the file mode creation mask
17541117Sbosticis clear, is set.
17641117SbosticOtherwise, the mode bits represented by the specified
17743082Scael.Ar who
17839829Sbosticand
17943082Scael.Ar perm
18041117Sbosticvalues are set.
18147089Scael.El
18243082Scael.Pp
18341117SbosticEach
18443082Scael.Ar clause
18541117Sbosticspecifies one or more operations to be performed on the mode
18641117Sbosticbits, and each operation is applied to the mode bits in the
18741117Sbosticorder specified.
18843082Scael.Pp
18941117SbosticOperations upon the other permissions only (specified by the symbol
19041117Sbostic``o'' by itself), in combination with the
19143082Scael.Ar perm
19241117Sbosticsymbols ``s'' or ``t'', are ignored.
19343082Scael.Sh EXAMPLES
19447089Scael.Bl -tag -width "u=rwx,go=u-w" -compact
19547089Scael.It Li 644
19641117Sbosticmake a file readable by anyone and writable by the owner only.
19747089Scael.Pp
19847089Scael.It Li go-w
19939829Sbosticdeny write permission to group and others.
20047089Scael.Pp
20147089Scael.It Li =rw,+X
20241117Sbosticset the read and write permissions to the usual defaults, but
20341117Sbosticretain any execute permissions that are currently set.
20447089Scael.Pp
20547089Scael.It Li +X
20641117Sbosticmake a directory or file searchable/executable by everyone if it is
20741117Sbosticalready searchable/executable by anyone.
20847089Scael.Pp
20947089Scael.It Li 755
21047089Scael.It Li u=rwx,go=rx
21147089Scael.It Li u=rwx,go=u-w
21241117Sbosticmake a file readable/executable by everyone and writeable by the owner only.
21347089Scael.Pp
21447089Scael.It Li go=
21539829Sbosticclear all mode bits for group and others.
21647089Scael.Pp
21747089Scael.It Li g=u-w
21845902Sbosticset the group bits equal to the user bits, but clear the group write bit.
21947089Scael.El
22043082Scael.Sh BUGS
22139829SbosticThere's no
22243082Scael.Ar perm
22339829Sbosticoption for the naughty bits.
22443082Scael.Sh SEE ALSO
22543082Scael.Xr install 1 ,
22643082Scael.Xr chmod 2 ,
22743082Scael.Xr stat 2 ,
22843082Scael.Xr umask 2 ,
22945903Sbostic.Xr fts 3 ,
23043082Scael.Xr setmode 3 ,
23155736Sbostic.Xr symlink 7 ,
23243082Scael.Xr chown 8
23343082Scael.Sh STANDARDS
23439829SbosticThe
23543082Scael.Nm chmod
23663673Smckusickutility is expected to be POSIX 1003.2
23763673Smckusickcompatible with the exception of the
23843082Scael.Ar perm
23947089Scaelsymbols
24047089Scael.Dq t
24147089Scaeland
24247089Scael.Dq X
24347089Scaelwhich are not included in that standard.
244