4.1 chmod permission specifications
chmod accepts a variety of methods to specify permissions of a file or directory. The most commonly used notation is also
used by several other commands, such as ls.
Execute the following command (anywhere in the file system):
ls -l -d
This is the “long” form of ls, which displays some properties related to a file. In this case, the ls command displays
properties of the current working directory itself.
You should see something like this:
drwxr-x--x 16 user1 group1 20480 2009-03-01 10:23 .
The first part of this line indicates the permissions. This is a 10-character sequence that is divided into 4 main
portions:
- d or -:
This part indicates whether the item is a regular file (-) or a folder (d). There are other types of files.
- -: regular file
- d: directory/folder
- b: block special file (like a hard drive device)
- c: character special file (like the console or serial port)
- l: symbolic link
- p: named pipe
- s: domain socket
- rwx:
The next three characters reflect permissions of the owner of this file. r means readable, w means writeable, and x
means executable. We have used these flags in a previous section already.
- r-x:
The next three characters reflect permission of the group of this file. If the user attempting to access
this file is not the owner, the file system falls back to see if the user is a part of the group of this file.
In this case, r-x means the file is readable and executable to the group that owns this file, but not
writable.
- --x:
The last three characters reflect permission of “others” with respect to this file. If the user attempting to
access this file is not its user owner or its group owner, then the file system defaults to the permission of
“others”. In this case, all non-owner users can access the member files only if they know the path into the
folder. The folder itself is not readable (cannot ls) or writable (cannot create or remove members). to
“others”.
The most intuitive method to change the permissions of a file is to use the “symbolic” method. For example, to remove
“read” access to a file from the group owner, use the following command:
chmod g-r file
Or, you can add execution permission to all users to a file using the following command:
chmod a+x file
The a ownership is an abbreviation of “all”, including the user owner, the group owner and others.