|
List Contents and Navigate Unix Directories

NOTE: This document assumes you are using Unix on the ITCS Login Service (host name: login.itd.umich.edu). These instructions apply to many other Unix machines; however, you may notice different behavior if you are not using the ITCS Login Service.
The Unix directory system helps you to keep track of your files and to find other files that you require. When you first log in via SFTP to the Login Service, you are "in" your home directory.
NOTE: This document is also available in Adobe Acrobat PDF and Microsoft Word formats.
Table of Contents

Listing a Directory's Contents
To see a list of the contents of a directory, type the ls command (short for list) at the % prompt.
% ls
AppleVolumes Private Public mail
In this example, there are four items in the current directoryAppleVolumes, Private, Public, and mail. We can't tell from this listing which items are files and which are directories.
Using Options on the ls Command
You can learn more about the directory's contents by setting options for the ls command. An option is indicated by a hyphen followed by a letter. Options are separated from the command by a space. For example, adding the -F option to the ls command will produce:
% ls -F
AppleVolumes Private/ Public/ mail/
Now you can tell that three of the items are directories, because they are marked with a /. If you want to find out what files and directories are in the directory Private, you can specify which directory you want ls to list:
% ls -F Private
bibliography chapter1 chapter2
The Private directory contains three files. Another useful option is the -l (letter "ell," not one) option, which lists directory contents in a long format.
% ls -l
total 7
-rw------- 1 bjensen 329 Jan 20 17:32 AppleVolumes
drwx------ 9 bjensen 2048 May 27 16:28 Private
drwxrwxrwx 3 bjensen 2048 Jun 10 11:07 Public
drwx------ 3 bjensen 2048 Jun 24 10:36 mail
The total entry shows how much space, measured in 512-byte (.5K) blocks, is used for these files. After that comes one line for each file.
The first character tells if the entry is a file (shown by -) or a directory (shown by d). Next comes a series of letters and hyphens that lists Unix permissions for each item. The next numeral gives the number of links to a file or directory.
The login name of the owner of these files appears next (bjensen). The next column gives the actual length of the file in bytes (1K=1024 bytes). Then come the date and time when the file was last changed. The last item on each line is the file or directory name.
A few other options for the ls command are:
| -a | lists hidden files (which begin with a period or dot) |
| -d | used with -l option to find the status of a directory, instead of listing the directory's contents |
| -s | gives the size of each file in kilobytes (K) |
| -t | lists files sorted by time of most recent modification |
| -r | reverses the order of the sort to get reverse alphabetic (ls -r) or oldest first (ls -rt) |
| -R | recursively lists contents of any subdirectories |
The -R option for the ls command lists the contents of the current directory and the contents of any subdirectories, as shown below:
% ls -R
AppleVolumes Private Public mail
Private:
bibliography chapter1 chapter2 resume
Public:
00introduction fyi_24.txt
mail:
You can give multiple options to the ls command. For example, ls -lt shows a long listing with the newest (or most recently changed) files first.
Determining Which Directory You're Currently In
The command pwd (short for print working directory) will show where you are in the directory structure.
pwd
/afs/umich.edu/user/b/j/bjensen
Reading from right to left, this means: I am in the directory called bjensen (my home directory), which is contained in the directory j, which is contained in the directory b, which is contained in the directory user, contained in the cell umich.edu, contained in the root directory (/afs).
Moving From One Directory to Another
In order to move from my home directory (bjensen) to the directory called Private, use the command cd (short for change directory).
cd Private
Directory Abbreviations for Faster Navigating
Say you are the user jansmart and your current working directory is
/afs/umich.edu/user/j/a/jansmart/Private/Paper1/Sources
You are in the directory Sources. If you wish to "back up" one level to the directory Paper1 (the parent of directory Sources), you could type
cd Paper1
but a faster way is to use the abbreviation for parent directory ( .. ). There is no space between the two periods:
cd ..
Another useful abbreviation is ~ (called tilde). This refers to a user's home directory (jansmart in our example). The easiest way to change back to your home directory from any directory is to type
cd ~
A third abbreviation ( . ) means the current working directory. For example, assume that you are in the directory Sources. You want to copy the file intro from Paper1 into your current directory, Sources. Without using any abbreviations, you would need to type (all on one line):
cp /afs/umich.edu/user/j/a/jansmart/Private/Paper1/intro [space]
/afs/umich.edu/user/j/a/jansmart/Private/Paper1/Sources/intro
Using the abbreviation for our home directory ( ~ ) and the abbreviation for the current working directory ( . ) we would type only:
cp ~/Private/Paper1/intro .
What makes these abbreviations work are the "." and ".." directories that appear when you type ls -a.
Pathnames
Within the home directory bjensen, there are three directories
Public Private mail
The directory Private contains several files:
bibliography chapter1 chapter2 resume
It is possible that more than one person could have a file called bibliography. How does Unix distinguish between files with the same name? The full name of each file includes the "path" through the directory hierarchy to that file.
The full names of two different bibliography files might be:
/afs/umich.edu/user/b/j/bjensen/Private/bibliography
and
/afs/umich.edu/user/j/a/jansmart/Private/Paper1/bibliography
The names of the two bibliography files shown above are absolute pathnames. An absolute pathname starts with a / to represent the root directory, then traces the path through various subdirectories to the file.
Another way to describe a file is by its relative pathname. Relative pathnames do not begin with a /. A relative pathname shows how to get to the file from the current working directory. If you are in the directory bjensen, the relative pathname to your file bibliography is
Private/bibliography
Navigating Through Directories
Unix files and directories are organized in a hierarchical structure. By convention, /afs is the root of the AFS file system (of which the Institutional File System, or IFS, is a part). All directories and files under /afs make up the AFS file space.
The first layer of directories beneath the root /afs in the AFS file space contains cells. A cell is an administrative domain and is generally controlled by a company, university, department, or other large group of users. Cells are administered by the groups that control them, and the system administrators for each cell determine how much file space each user is given.
The local cell for most U-M students, faculty, and staff is umich.edu. Other cells also exist on campus. The College of Engineering is a large user of AFS on campus and administers the engin.umich.edu cell.
The umich.edu cell is composed of several directories:
| Directory | Description |
| group | One home directory for each group. This tree is a hierarchy of organizations, so the path to a given group would descend through the larger groups of which it is part. |
| system | System binaries for several architectures. |
| class | One home directory for each class. This tree is relatively flat. Each class has its own home directory. Layout within the home directory is up to the class instructors. If multiple sections are involved, the instructors may decide to have separate subdirectories for each section. |
| user | One home directory for each user. The path to a given user's home directory is <firstletter>/<secondletter>/<uniqname>; thus, the path to foobar's home directory is f/o/foobar. |
To allow for the administration of thousands of home directories, the directory "user" has been partitioned into 26 directoriesthe letters of the alphabet. Again, each of those directories is partitioned into 26 directories.
Additional Resources
Visit ITCS's
Information System to obtain ITCS computer documentation
and other resources. A list of relevant documents follows:
We welcome your comments; please send e-mail.
ITCS's Online Help Desk provides a variety of computing help resources.
For further help, send e-mail or phone (734) 764-HELP.
|