Swarthmore College Department of Computer Science

the unix filesystem

The root directory (/) is the beginning or top directory for the filesystem. The Unix file system is made up of parent and sub-directories (folders). The root directory has no parent directories, but has many sub-directories, such as etc, var, bin, and home. A path to a directory consists of the directories you have to open to get to it. The absolute path consists of all the parent directories of a file or directory starting with root.

The absolute path for home in the diagram above is /home, because the root directory is home's parent directory. /home is where all the users' home directories are located. The absolute path for your home directory is:

/home/yourusername

Warning: don't confuse the / at the beginning of the path (which is the root directory) with the / separating home and yourusername (which divides the two directories).

A relative path does not start with /. It consists of the directories separating your current location in the file system from the file or directory.

If you were in /home/username and wanted to get to:

/home/username/cs21/labs/hello_world.py

the relative path to this file would be:

cs21/labs/hello_world.py

There is an implicit . (called "dot") in this relative path. A single dot means the current directory, so the above relative path could also be written as:

./cs21/labs/hello_world.py

So to look at the hello_world.py program, you could do any of the following, and they would all show you the program (using the page-by-page viewer called less):

less cs21/labs/hello_world.py
less ./cs21/labs/hello_world.py
less /home/username/cs21/labs/hello_world.py

.. (dot dot) means the parent directory (one level up). If you are in the labs directory, and then want to get to /home/username/cs21/lectures, the relative path to this file would be: ../lectures