• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 4. Unix Security & Utilities > Changing Permissions for a File or Direc...

Changing Permissions for a File or Directory

Unix includes a command for setting file or directory permissions: chmod. Although this command can be a bit complicated, it is important. The security of your files and subdirectories depend on its proper usage.

The chmod command uses the following syntax: chmod mode file ...

The complex part of the chmod command is understanding what can go in the mode operand. This is where you specify the owner (also called user), group, and other (everyone else) permissions. You have two ways to do this: numerically and symbolically.


  • You can learn more about the chmod command by viewing its man pages. In the Terminal window, type man chmod and press .

Numeric permission modes

Numeric permission modes uses numbers to represent permissions options.

The best way to explain this is to provide an example. Remember, the nine characters of the permissions coding in a directory listing can be broken down into three sets of three:

rwx rwx rwx
user group other

Each character can be represented with an octal digit (a number between 0 and 7) by assigning values to the r, w, and x characters, like this:

421 421 421
rwx rwx rwx
user group other

So, if you want to give read and write permission for a file called file1 to the owner, that would be a 4 (read) plus a 2 (write), which adds up to a 6. You could then give read only permission to the group and others by assigning the value 4 (read). The command to do all this is chmod 644 file1. (The 644 permission is one you'll see often on text files that are readable by everyone. A permission of 600 would make a file private.)

Symbolic permission modes

Symbolic permission modes enables you to add or remove privileges using symbols. For example, to remove write permission from the group and others, type chmod go-w file1. This translates to “take away write permissions from the group and others.”

The ownership symbols you use for this are:

u user (owner) of the file or directory
g group owner of the file or directory
o others (everyone)
a all three (user, group, and others)

The symbols for the permissions you can add or take away are:

r read
w write
x execute

Finally, the operations you can perform are:

+ add the permission
- remove the permission
= set (add) the following permissions

You can combine more than one symbol in a mode and more than one “equation” if you separate them with commas. For example, chmod a+rwx,o-w file1 gives universal read, write, and execute access to all and then takes away write permission from others to file1. (The equivalent numerical permission would be 775.)

To change the permissions for a file or directory

In the Terminal window, type chmod mode file ... (for example, chmod 644 file1) and press .


  • If you include the -R option in the command (for example, chmod-R 644 folder1), the change is made recursively down through the directory tree. In other words, the change is made to the folder and every file and folder within it.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint