Skip to Content
UNIX Filesystems: Evolution, Design, and Implementation
book

UNIX Filesystems: Evolution, Design, and Implementation

by Steve D. Pate
January 2003
Intermediate to advanced content levelIntermediate to advanced
480 pages
13h 22m
English
Wiley
Content preview from UNIX Filesystems: Evolution, Design, and Implementation

Changing File Permissions

There are a number of commands that allow the user to change file properties. The most commonly used is the chmod utility, which takes arguments as follows:

chmod [ -fR ] <absolute-mode> file …

chmod [ -fR ] <symbolic-mode-list> file …

The mode to be applied gives the new or modified permissions of the file. For example, if the new permissions for a file should be rwxr--r--, this equates to the value 744. For this case, chmod can be called with an absolute-mode argument as follows:

$ ls -l myfile
-rw-------      1  spate    fcf                        0 Mar  6 10:09 myfile
$ chmod 744 myfile
$ ls -l myfile
-rwxr--r-       1  spate     fcf                       0 Mar 6 10:09 myfile*

To achieve the same result passing a symbolic-mode argument, chmod can be called as follows:

$ ls -l myfile
-rw------        1  spate    fcf                         0 Mar 6 10:09 myfile
$ chmod u+x,a+r myfile
$ ls -l myfile
-rwxr--r-        1  spate    fcf                         0 Mar 6 10:09 myfile*

In symbolic mode, the permissions for user, group, other, or all users can be modified by specifying u, g, o, or a. Permissions may be specified by adding (+), removing (−), or specifying directly (=), For example, another way to achieve the above change is:

$ ls -l myfile
-rw---------     1  spate    fcf                          0 Mar 6 10:09 myfile
$ chmod u=rwx,g=r,o=r myfile
$ ls -l myfile
-rwxr--r-        1  spate    fcf                          0 Mar 6 10:09 myfile*

One last point worthy of mention is the -R argument which can be passed to chmod. With this option, chmod recursively descends through any directory arguments. For example:

$ ls -ld mydir drwxr-xr-x 2 spate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Design and Implementation of the FreeBSD Operating System, 2nd Edition

Marshall Kirk McKusick, George V. Neville-Neil, Robert N.M. Watson

Publisher Resources

ISBN: 9780471456759Purchase book