Working directory
Each process has a directory associated with it called the working directory, which is usually inherited from the parent process. This makes it possible to specify relative paths – one that doesn't start with the root folder. This will be / on Unix and macOS and C:\ (or any other drive letter) on Windows.
A relative path doesn't start with a root, and the path starts with the current working directory, that is, documents.
The operating system interprets these paths as being relative to the current directory, so their absolute version is a concatenation of the working directory and the relative path. Let's take a look at the following example:
user:~ $ cd documents
user:~/documents $ cd ../videos
user:~/videos $
Here, the user is in their home folder, ~. The user specifies to change directory to documents, and the cd command automatically adds the working directory as a prefix to it and moves to ~/documents.
Before moving on to the second command, let's introduce two special files that are available in all the directories for all operative systems:
- .: The dot is a reference to the current directory. If it's the first element of the path, it is the process working directory, otherwise it refers to the path element that precedes it (for example, in ~/./documents, . refers to ~).
- ..: The double dot refers to the parent of the current directory if it's the first element of the path, or to the parent of the directory that it precedes if not (for example, in ~/images/../documents, .. refers to the parent of ~/images, ~).
Knowing this, we can easily infer that the second path is first joined in ~/documents/../videos, the parent element, .., gets resolved, and the final path, ~/videos, is obtained.