Previous Section  < Day Day Up >  Next Section

Recipe 9.4. Setting File and Directory Permissions with chmod's Symbolic Notation

9.4.1 Problem

You would like to change specific permission bits, rather than using the all-or-nothing approach of chmod's numeric notation, such as marking a script as executable.

9.4.2 Solution

The most common use for symbolic notation is to add the executable bit to a file's permissions without changing any other permissions:

$ chmod +x scriptname

The default action is a, or all, so the example makes scriptname executable by everyone. This adds the executable bit to the file owner only:

$ chmod u+x scriptname

You can surgically remove a specific mode bit. In this example, the group and other users lose their executable bits:

$ chmod go-x scriptname

This is a quick way to set the setgid bit on a directory, for creating a shared directory. All files created in this directory will have the same group ownership as the directory:

$ chmod +s /shared-directory

You can remove all permissions for group and other users by doing the following:

$ chmod go= scriptname

To make group permissions the same as the file owner's, use:

$ chmod g=u scriptname

9.4.3 Discussion

Using chmod's symbolic notation can get quite elaborate. This examples erases all existing permissions and starts over:

$ chmod -v a=,u=rwx,g=rx,o=r scriptname

You can do the same thing with chmod 754. Here's the key:

Symbolic notation is also called mnemonic notation:








File must already have execute permissions, or be a directory


Set user or group ID on execution—dangerous! do not use on executables, unless you really really know what you are doing!


Sticky bit


User, or file owner


Group file owner


Everyone else; others


Adds the new values to the existing values




Subtracts from existing values

9.4.4 See Also

  • info chmod

  • Recipe 9.7, for an explanation of sticky bits

  • Chapter 4 of LPI Linux Certification in a Nutshell, for exhaustive detail on permissions and ownership, right down to the binary level

    Previous Section  < Day Day Up >  Next Section