< Relative pathnames >
Now it's finally time to discuss relative pathnames. As you've learned, an absolute pathname starts from the root directory. A relative pathname, however, starts from the working directory. This is why you need some special symbols for indicating the relative positions in the filesystem. These symbols are a dot (.) and two dots (..) and they mean the working directory and the parent directory, respectively.
Let's see how these things work. Now your current working directory should be /usr/X11R6
. List the contents of it:
me@puter: /usr/X11R6$ ls
bin include lib man
me@puter: /usr/X11R6$
There should be a directory called "lib", and we want to find out what it contains but we don't want to change the working directory. There are two ways of doing this. We can use the absolute pathname:
me@puter: /usr/X11R6$ ls /usr/X11R6/lib
Or using the relative pathname:
me@puter: /usr/X11R6$ ls ./lib
Here, the dot in the path ./lib
refers to the working directory, which is /usr/X11R6
. This saved some typing! But it'll save even more typing if you omit the leading dot. In most cases you don't need it, so this would've been the same as the above:
me@puter: /usr/X11R6$ ls lib
Now let's change the working directory to /usr/X11R6/bin
. There are again two ways of doing this. First, using absolute pathname:
me@puter: /usr/X11R6$ cd /usr/X11R6/bin
Or using relative pathname, remember that you don't have to type the dot:
me@puter: /usr/X11R6$ cd bin
Now your current working directory is /usr/X11R6/bin
. Let's change it to /usr/X11R6
which is the parent directory. Again you could use the absolute pathname:
me@puter: /usr/X11R6/bin$ cd /usr/X11R6
But it's faster to use the two dots that mean "parent directory":
me@puter: /usr/X11R6/bin$ cd ..
Note the space between cd
and the dots.
As you can see, in many cases using relative pathnames instead of absolute ones saves some typing.