Relative Pathnames

In the previous section, pathnames were introduced as the way to navigate through the file system. These long pathnames are also referred to as absolute pathnames. UNIX/Linux systems recognize some special character combinations known as relative pathnames. These relative pathnames can be used as shortcuts to save time while accessing files and directories.

~/Tilde-slash refers to your home directory. The ~ actually replaces the /afs/unity.ncsu.edu/users/u/unityid
../Dot-dot-slash refers to the directory above your current working directory (the parent directory). This can be used in conjunction with other shortcuts.
./Dot-slash refers to the current working directory. Instead of typing the long (absolute) pathname, you can use dot. This is useful when working with files in your current working directory.

You can think of an absolute pathname like a physical, named address, such as 2610 Cates Ave, Raleigh, NC 27606 (Talley Student Union). A relative path for the same location would be something like: if I’m at Withers Hall, then cross the railroad tracks and turn right to get to Talley. The absolute path would tell me where to go from any other location, but the relative path will only work if I’m at Withers.

Example

If your current working directory is MyE115 in the tree below, what is the pathname to index.html in the www directory?

 Using shortcuts to navigate to different directories

The following relative pathnames are all acceptable:

  • ../www/index.html
  • ~/www/index.html
  • ./../www/index.html

For comparison, the absolute pathname would be: /afs/unity.ncsu.edu/users/j/jshmoe/www/index.html