Relative and Absolute Paths

Unix files and directories are organized into an inverted tree with the trunk representing the root or top-level directory the branches and sub-branches representing the lower subdirectories and the leaves representing the files. Your home directory has a name something like this:

  /u/class/myname
The root or toplevel directory / contains a subdirectory u, which, in turn, contains a subdirectory class, etc. As shown, this name gives an absolute path to your home directory. All absolute paths starti with a slash / for the root directory. In general the path specifies the route from the current working directory to the file or directory you wish to access. Paths are either absolute or relative. For example. suppose your current working directory is /u/stu. Then the relative path to your home directory would be specified by p6720/myname. The absolute path gets you there, regardless of where you start. The relative path depends on where you start.

For further examples, suppose your home directory contains subdirectories asst01 and asst02. Suppose your current working directory is

  /u/class/myname/asst02
What is the relative path to your directory asst01? It is ../asst01. The .. backs up to your home directory and the /asst01 takes you from there down to the subdirectory asst01. The absolute path to your directory asst01 is given by
  /u/class/myname/asst01
A convenient shorthand uses ~ which stands for your home directory. Thus ~/asst01 is also an absolute path to the directory asst01.

A path often refers to a file as well. Thus in the example above, if the current directory is asst02 and you want to refer to a file mytext located in the directory asst01, the relative path is ../asst01/mytext.

Most shells have an environment variable PATH, which is actually a list of absolute paths to directories where binary executable files are to be found.