Free Hosting Online for WorkStations

< Previous | Contents | Next >

Relative Pathnames

Where an absolute pathname starts from the root directory and leads to its destination, a relative pathname starts from the working directory. To do this, it uses a couple of special notations to represent relative positions in the file system tree. These special notations are "." (dot) and ".." (dot dot).

The "." notation refers to the working directory and the ".." notation refers to the working directory's parent directory. Here is how it works. Let's change the working directory to


/usr/bin again:


[me@linuxbox ~]$ cd /usr/bin

[me@linuxbox bin]$ pwd

/usr/bin

[me@linuxbox ~]$ cd /usr/bin

[me@linuxbox bin]$ pwd

/usr/bin


Okay, now let's say that we wanted to change the working directory to the parent of

/usr/bin which is /usr. We could do that two different ways. Either with an absolute pathname:



[me@linuxbox bin]$ cd /usr

[me@linuxbox usr]$ pwd

/usr

[me@linuxbox bin]$ cd /usr

[me@linuxbox usr]$ pwd

/usr


Or, with a relative pathname:



[me@linuxbox bin]$ cd ..

[me@linuxbox usr]$ pwd

/usr

[me@linuxbox bin]$ cd ..

[me@linuxbox usr]$ pwd

/usr


Two different methods with identical results. Which one should we use? The one that requires the least typing!

Likewise, we can change the working directory from /usr to /usr/bin in two different ways. Either using an absolute pathname:



[me@linuxbox usr]$ cd /usr/bin

[me@linuxbox bin]$ pwd

/usr/bin

[me@linuxbox usr]$ cd /usr/bin

[me@linuxbox bin]$ pwd

/usr/bin


Or, with a relative pathname:



[me@linuxbox usr]$ cd ./bin

[me@linuxbox bin]$ pwd

/usr/bin

[me@linuxbox usr]$ cd ./bin

[me@linuxbox bin]$ pwd

/usr/bin


Now, there is something important that I must point out here. In almost all cases, we can

Changing The Current Working Directory


omit the "./". It is implied. Typing:



[me@linuxbox usr]$ cd bin

[me@linuxbox usr]$ cd bin


does the same thing. In general, if we do not specify a pathname to something, the work- ing directory will be assumed.


Top OS Cloud Computing at OnWorks: