Hierarchy Primer

The Unix File System Hierarchy

Introduction

The Unix File system is a hierarchy. That is, it can reviewed as a tree structure. Sub directories (folders) appear as branches emanating from a their parent directories (a folder containing the folder). The tree allows for only one parent for each sub directory, but a parent directory may contain many sub directories. The following figure shows a tree diagram based on the WSU Unix file system. Vertical lines represent the contents of a directory. A horizontal line indicates that the sub directory is contained in the directory represented by the vertical line it intersects. In the diagram, wsunix and www are both contained in users (they are siblings).

The Root Directory

The root directory is represented by the symbol / . Note: the / symbol is also used to separate names in a list of directory names called a directory path name (or just path name). We will discuss path names next.

Path Names

Path names are used to describe the location of directories and files in the file system hierarchy. A path name is essentially a description of the directories that must be passed through to get to a particular directory. There are two ways to write path names. One way is to refer to the desired directory by giving a path name that starts at the root. Such a path name is said to be absolute. Another way is to refer to the desired directory by giving a path name that starts at the user's current working directory. This kind of path name is called relative.

Absolute Path Names

Absolute path names describe a path from the root to a particular directory (folder). The first symbol in an absolute path name is always the root symbol. Each directory that precedes the desired directory is listed in turn. Additional backslash characters are used to separate the names in the list.

For example: the following hierarchy contains a directory called mydir. The absolute path name for this directory is: /users/wsunix/your-account-name/mydir The root contains users, users contains your-account-name, and your-account-name contains the directory mydir.

Test your understanding by comparing the diagram to the following table.

Directory
Absolute Path Name
users /users
wsunix /users/wsunix
your-account-name /users/wsunix/your-account-name
my_other-dir /users/wsunix/your-account-name/my_other-dir
progs

/users/wsunix/your-account-name/my_dir/progs

docs /users/wsunix/your-account-name/my_dir/docs
memos /users/wsunix/your-account-name/my_dir/docs/memos

 

The Home Directory

Multi-user Unix environments assign each user a home directory. On WSU Unix your home directory is /users/wsunix/your-account-name , where your-account-name is the account name you use to login to WSU Unix. Unix systems usually assign the alias, $HOME, to your home directory.

WSU Unix will display the absolute path name of your home directory if you issue the command echo $HOME regardless of where you are working in the hierarchy.

The Working Directory

In Unix, one directory is always the working (or current) directory. Think of it as the currently open folder. The Unix command pwd (print working directory) displays the absolute path name of this directory. When you first log on to a Unix system, your home directory is your working directory.

. (dot) is the symbol used to represent the working directory; however, the dot is rarely used in commands. The parent directory of the working directory is often represented symbolically as .. (double dot). The double-dot notation is not used in absolute path names.

Relative Path Names


The directory progs has a relative path name of progs since it is in my_dir and since we are traversing down the tree. The directory your-account-name has a relative path name of .. since we must traverse up the tree to get there. The directory my_other-dir has a relative path name of ../my_other-dir . Test your understanding by comparing the diagram to the following table:
Directory
Relative Path Name
users ../../..
wsunix ../..
my_dir (none or dot)
docs docs
memos docs/memos

Since relative path names are relative to the working directory, relative path names change when the working directory changes. This example assumes progs is the working directory.

Directory
Relative Path Name
users ../../../..
wsunix ../../..
your-account-name ../..
my_dir ..
my_other-dir ../../my_other-dir
progs (none or dot)
docs ../docs
memos ../docs/memos

 

In the next lesson, you will learn to use Unix commands to work with directories. Path names will play an important roll in those discussions. If you are still confused by path names, it would be best to reread this section until you are comfortable with the concepts.