Browse the Linux filesystem

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:

cat /home/bill/books/dante_inferno.txt

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:

head books/dante_inferno.txt

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:

head ../patrick/homeworks.txt

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/.

 

 

Tagged , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *