Jump to content

How to set file and directory permissions with chmod's symbolic notation

0
  carlaschroder's Photo
Posted Aug 24 2009 09:29 AM

The following will help you change specific permission bits rather than using the all-or-nothing approach of chmod's numeric notation. 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
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:


r

Read


w

Write


x

Execute


X

File must already have execute permissions, or be a directory


s

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


t

Sticky bit


u

User, or file owner


g

Group file owner


o

Everyone else; <a name="snippet">others


+

Adds the new values to the existing values


=

Overwrites


-

Subtracts from existing values

Tags:
0 Subscribe


0 Replies