Course Links

Exercises

Resources

External

Introduction

Files on Unix operating systems (including Linux) are organized into structures called directories. Unix directories are roughly analagous to folders on computers running Windows or Mac OS. In fact, when you use one of the lab machines you can open a browser window showing the Unix directory structure as a series of folders within folders, much as you would on a Mac or Windows machine. However, there are times you will need to navigate the Unix directory structure using command line instructions, and this tutorial is designed to help you understand how to do that.

It is recommended that you read and complete the tutorial on file management before reading further.

The Directory Tree

Every user has a home directory associated with their Unix account. This is where all your personal files should go. You can list the contents of a directory using the ls command:

% ls
file1 file2 file3
In the hypothetical example above, there are three files listed.

To help you to organize your files, you can create additional directories within your home directory. These may have further subdirectories within them, and so on. Similarly, the home directories of most users are contained within a directory called home. The home directory plus a few others containing system files are all within a single outermost directory known as the root. All the files and directories on the whole system are contained somewhere within the root directory or one of its descendants. Each individual file or directory can be specified by a listing of the directories that contain it, starting from the root and separating each directory name with a / (forward slash). Such a listing is called a pathname.

Pathnames are long. To avoid having to type them all the time, Unix uses the concept of a working directory. (In terms of the graphical folder metaphor common to Windows and Mac operating systems, this is like the currently open folder.) Anything in the working directory may be referred to by name, and commands like ls are applied to the working directory. When you log in, the working directory is set to your home directory. You can see the path using the pwd command:

% pwd
/home/112a/students/112a-xx