Use ls -l to learn the permissions on a file.

When you type ls -l on a file, you’ll see the file’s permissions represented in the first column. For example:

    % ls -l ch01
    -rw-r---- 1 lmui        68608 Oct 18 13:11 ch01

The first column of this listing is a 10-character string consisting of dashes and the characters r, w, and x. This string represents the permissions for each file. To interpret the permissions, you need to break up this string into four distinct parts.

The first character tells you what kind of file this is, and doesn’t have much to do with file permissions. When it’s a -, it means that the file is a regular file. Other values are d for a directory and l for a symbolic link.

You can ignore the first character for now. The remaining nine characters represent who has read, write, or execute permission for the file. Think of it as consisting of three sets each of the characters r, w, x, and -. The first set represents owner permission, the second set represents group permission, and the third set represents permissions for everyone else (aka “the world”).

An r represents read permission, w represents write permission, and x represents execute permission. For each set, the three characters rwx always appear in order. If any of these characters is missing (i.e., replaced by a dash), then that permission is denied.

When the file called ch01 shows permissions -rw-r——, this means that the owner of the file (lmui) can read and write the file, members of the file’s group can only read the file, and everyone else is left out in the cold.

You’ll find that r, w, and x aren’t the only letters you’ll see in a file’s permissions. Occasionally you’ll see the special characters s, S, t, and T in place of x. This means that the file or directory has special permissions; in general, only administrators concern themselves with this level of permissions.

Get WYNTK: UNIX System Admininistrator now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.