Understanding Pathnames

Unix Shell Mastery - Part: 3

Learn how to navigate the file system from the terminal

When you login to the system you are placed into a directory called the home directory. The location of this directory can vary from system to system. In my case my home directory is called george. The home directory is actually a subdirectory, meaning it is inside of another folder. At the top of the directory tree there is a folder called / pronounced slash this is also known as the root directory.

/ george Music Users Applications app Finder app Sketch Documents Essays Invoices Notes guest

The directory you are in is commonly called the current working directory. A pathname that begins with a / is called a full pathname because it specifies a complete path from the root. For example the full pathname to the Documents directory in the diagram above would be /Users/george/Documents.

It is often inconvenient to have to type out the full pathname. Pathnames that do not begin with a / are called relative pathnames. They are called this because they are relative to the current working directory. For example if your current working directory was george you could reference the Documents directory simply by typing Documents. Notice that the directory name is case sensitive. If you wanted to reference the Notes directory you could do so like this Documents/Notes.

The directory that is above the current working directory is often referred to as the parent directory. To reference the parent directory we can use ... Therefore if the current working directory was george the the relative pathname .. would reference Users. To reference the root directory the relative pathname would be ../...

As a final example if the current working directory was Essays we could access Sketch.app with the relative pathname ../../../../Applications/Sketch.app.

The notation used to reference the current working directory is .. In Mac the open command opens the specified path in Finder.

$ open .

This command would open the current working directory in Finder.

Top tip:

When you are typing out a full path name long or complicated directory names can be a pain. Say for example your current working directory is george if you type out Doc then hit tab it will autocomplete to Documents.