Note This document assumes you are using Unix on the ITS 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 ITS Login Service.
The Unix directory system helps you keep track of files that are relevant to you. When you first login to the Login Service via SFTP, you will find yourself "in" your home directory.
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 directory—AppleVolumes, Private, Public, and mail. From this listing, we cannot tell which items are files and which are directories.
Using Options on the ls Command
You can learn more about the directory's contents by specifying 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/
You can now ascertain that three of the items are directories, because they are marked with a / forward slash. If you wish to determine the contents of the Private directory, you can specify this option for the ls command:
% ls -F Private
bibliography chapter1 chapter2
The Private directory contains three files. Another useful option is the -l (phonetic 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 of its subdirectories, as shown below:
% ls -R
AppleVolumes Private Public mail Private: bibliography chapter1 chapter2 resume Public: 00introduction fyi_24.txt mail:
You can attach 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 located in the directory hierarchy.
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
For example, if 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 an abbreviated option is ( .. ). 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 simplest way to relocate to your home directory from any directory is to type
cd ~
A third abbreviation ( . ) implies 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 your home directory ( ~ ) and the abbreviation for the current working directory ( . ) you could type only:
cp ~/Private/Paper1/intro .
These abbreviations originate from 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
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 AFS, 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 simplify directory administration, the directory "user" has been partitioned into 26 subdirectories- one for each letter of the alphabet- and these are partioned again, the same way. This partitioning handles the first two letters of user uniqnames.