University of Iowa College of Liberal Arts & Sciences

  Computer Science | Mathematics | Statistics and Actuarial Science | Applied Mathematical and Computational Sciences | Informatics

Mathematical Sciences Computer Support Group

Viewing Linux File and Directory Permissions


Classes of Accounts

The files and directories in the home directory of your Mathematical Sciences account can be accessed on computers running the Linux operating system. Linux is a type of UNIX and uses UNIX file and directory permissions. For purposes of permissions, UNIX divides accounts into three classes:

userYour account
groupAny permissions group that your account belongs to
otherAny account that is not yours and that does not belong to a permissions group that your account belongs to

Types of Permissions

There are three basic types of permissions which can be assigned to each of these three classes of accounts:

read
write
execute

File Permissions

These three types of permissions mean slightly different things for files than for directories. For files, these permissions grant these rights:

readAllowed to read the contents of the file
writeAllowed to modify or delete the file
executeAllowed to run the file as a process, if possible

Directory Permissions

For directories, the permissions grant these rights:

readAllowed to list the contents of the directory
writeAllowed to create, modify or delete files in the directory
executeAllowed to access a file in the directory if you know the name of the file

Viewing File Permissions

The ls command is used to list files and the contents of directories. The -l parameter displays permissions. For example, to see the permissions of a file named foo in the directory /usr/bin/bar, you would execute:

ls -l /usr/bin/bar/foo

And the command would return something like this:

-rwxr-xr--   1 jsmith   guest    3072 Feb 11 09:25 /usr/bin/foo

In the example, jsmith is the account that owns foo, and guest is the name of the group that owns /usr/bin/foo. The -rwxr-xr-- at the left indicates the permissions. The first character, the -, indicates that /usr/bin/foo is a file, not a directory. The rwx shows the permissions for the user class of accounts--in this case, jsmith. The r indicates read permission; the w, write permission; and the x, execute permission. The next three characters, r-x, show permissions for the group class of accounts, which is guest in this example. Finally, the last three characters, r--, display permissions for the other class--any account that is not jsmith and is not in the guest group.

Viewing Directory Contents

If you want to see the contents of a directory, you also use ls. Suppose that /usr/bin/bar is a directory. Then the command

ls -l /usr/bin/bar

may return something like this:

drwxr-x--x  5 jsmith   guest   4096 Jan 23  2008 foodir
-rw-r-----  1 jsmith   guest  48128 Sep 14  2004 WhatToDo.doc
-rw-rw-r--  1 jsmith   guest    464 Jul  6  2005 WinCA.txt

This shows us the contents of the directory bar. The d at the left of the entry for foodir indicates that foodir is a directory.

Viewing Directory Permissions

If you want to see the permissions of the /usr/bin/bar directory itself, not its contents, then you need to use the -d command-line argument for ls. So, you'd execute this command:

ls -ld /usr/bin/bar

and you'd see something like this:

dr-xrwxr-x  3 jsmith   guest   4096 Jan 23  2008 /usr/bin/bar

The Current Working Directory

The current working directory is the directory that, by default, a UNIX command will use when it is executed. For example, if you do not specify a file or directory when you run the ls command, then ls will assume that you want to see the contents of your current working directory. So,

ls 

will return a list of the files and directories in your current working directory. To see the absolute path of your current working directory, use the pwd command.

UNIX provides a shorthand for your current working directory. A single period, ., indicates the current working directory. Two periods, .., indicate the directory immediately above your current working directory.

Hidden Files and Directories

In UNIX, if a file or directory name begins with a period, ., then by default, ls will not display the file or directory in a directory listing. To see all the files in a directory, including hidden files, use the a command-line argument. The command

ls -a

will show all files and directories in a directory, including hidden files. The command

ls -al

will display all files and directories, and also show their permissions.

Home Directories

Each Linux account is associated with a home directory. When you login to your Linux account, by default, your current working directory will be your home directory. UNIX provides a short-hand symbol for your home directory, the tilde character, ~. So, to see a list of files in your home directory, you can execute

ls ~

For Further Information

To learn more about Linux file and directory permissions, search on the Web or use the Linux man command to research the chmod and umask commands.