If you want to refer to a directory in UNIX (and, with little differences, in Windows too) you can use:
- Relative path
- Absolute path
Absolute path is the whole path from root (the very begin, referred to as /) to the desired directory. The absolute path of “books” is /home/bill/books. They always start with the slash. If you want to read a file called “dante_inferno.txt” located within the books directory you can type the following command, and this will work from every directory of the filesystem:
The good thing is that they never change, the bad thing is that they could be very long.
A relative path, as the name suggests, depends on where you are. Remembering that “.” means current directory and “..” upper directory, let’s see some examples.
We are now in the /home/bill directory (we can check this via “pwd“). To read the first ten lines of Dante’s Inferno i can type:
While if i want to see the first lines of homeworks.txt that is located in patrick’s home I have to go up one level and then:
Of course “head /home/patrick/homeworks.txt” (absolute path) will do the same thing.
Look at this simplifiede scheme of our Computer Room tree: each of you has a data directory in its home (geno-XX), while we all have a common tools directory in /home/geno/.