3
@c Copyright (C) 1994, 1996, 1999-2001, 2003-2006, 2008-2011 Free Software
3
@c Copyright (C) 1994-2012 Free Software Foundation, Inc.
6
5
@c Permission is granted to copy, distribute and/or modify this document
7
6
@c under the terms of the GNU Free Documentation License, Version 1.3 or
18
17
* Mode Structure:: Structure of file mode bits.
19
18
* Symbolic Modes:: Mnemonic representation of file mode bits.
20
19
* Numeric Modes:: File mode bits as octal numbers.
20
* Operator Numeric Modes:: ANDing, ORing, and setting modes octally.
21
21
* Directory Setuid and Setgid:: Set-user-ID and set-group-ID on directories.
348
The combination @samp{o+s} has no effect. On @acronym{GNU} systems
348
The combination @samp{o+s} has no effect. On GNU systems
349
349
the combinations @samp{u+t} and @samp{g+t} have no effect, and
350
350
@samp{o+t} acts like plain @samp{+t}.
496
496
number that represents the mode.
497
497
This number is always interpreted in octal; you do not have to add a
498
498
leading @samp{0}, as you do in C. Mode @samp{0055} is the same as
499
mode @samp{55}. (However, modes of five digits or more, such as
500
@samp{00055}, are sometimes special. @xref{Directory Setuid and Setgid}.)
501
502
A numeric mode is usually shorter than the corresponding symbolic
502
503
mode, but it is limited in that normally it cannot take into account the
503
504
previous file mode bits; it can only set them absolutely.
504
(As discussed in the next section, the set-user-ID and set-group-ID
505
bits of directories are an exception to this general limitation.)
505
The set-user-ID and set-group-ID bits of directories are an exception
506
to this general limitation. @xref{Directory Setuid and Setgid}.
507
Also, operator numeric modes can take previous file mode bits into
508
account. @xref{Operator Numeric Modes}.
507
510
The permissions granted to the user,
508
511
to other users in the file's group,
542
545
@samp{ug=rw,o=r}. Numeric mode @samp{0} corresponds to symbolic mode
548
@node Operator Numeric Modes
549
@section Operator Numeric Modes
551
An operator numeric mode is a numeric mode that is prefixed by a
552
@samp{-}, @samp{+}, or @samp{=} operator, which has the same
553
interpretation as in symbolic modes. For example, @samp{+440} enables
554
read permission for the file's owner and group, @samp{-1} disables
555
execute permission for other users, and @samp{=600} clears all
556
permissions except for enabling read-write permissions for the file's
557
owner. Operator numeric modes can be combined with symbolic modes by
558
separating them with a comma; for example, @samp{=0,u+r} clears all
559
permissions except for enabling read permission for the file's owner.
561
The commands @samp{chmod =755 @var{dir}} and @samp{chmod 755
562
@var{dir}} differ in that the former clears the directory @var{dir}'s
563
setuid and setgid bits, whereas the latter preserves them.
564
@xref{Directory Setuid and Setgid}.
566
Operator numeric modes are a GNU extension.
545
568
@node Directory Setuid and Setgid
546
569
@section Directories and the Set-User-ID and Set-Group-ID Bits
560
583
mechanisms would be less convenient and it would be harder to share
561
584
files. Therefore, a command like @command{chmod} does not affect the
562
585
set-user-ID or set-group-ID bits of a directory unless the user
563
specifically mentions them in a symbolic mode, or sets them in
564
a numeric mode. For example, on systems that support
586
specifically mentions them in a symbolic mode, or uses an operator
587
numeric mode such as @samp{=755}, or sets them in a numeric mode, or
588
clears them in a numeric mode that has five or more octal digits.
589
For example, on systems that support
565
590
set-group-ID inheritance:
584
609
# These commands try to set the set-user-ID
585
610
# and set-group-ID bits of the subdirectories.
588
chmod u=rwx,go=rx,a+s H
614
chmod u=rwx,go=rx,a+s G
590
617
mkdir -m u=rwx,go=rx,a+s J
593
620
If you want to try to clear these bits, you must mention them
594
explicitly in a symbolic mode, e.g.:
621
explicitly in a symbolic mode, or use an operator numeric mode, or
622
specify a numeric mode with five or more octal digits, e.g.:
597
# This command tries to clear the set-user-ID
625
# These commands try to clear the set-user-ID
598
626
# and set-group-ID bits of the directory D.
602
This behavior is a @acronym{GNU} extension. Portable scripts should
633
This behavior is a GNU extension. Portable scripts should
603
634
not rely on requests to set or clear these bits on directories, as
604
@acronym{POSIX} allows implementations to ignore these requests.
635
POSIX allows implementations to ignore these requests.
636
The GNU behavior with numeric modes of four or fewer digits
637
is intended for scripts portable to systems that preserve these bits;
638
the behavior with numeric modes of five or more digits is for scripts
639
portable to systems that do not preserve the bits.