About Linux FAQ

Browse More FAQs:

Understanding Linux / UNIX Relative Pathname

Posted by Vivek Gite [Last updated: August 15, 2007]

Q. Can you explain the term relative pathname under UNIX or Linux oses?

A. The relative pathnames are opposite to absolute pathname. A reative pathname does not begin with a slash ( / ). Generally you specifies location relative to your current working directory. This is most useful to short a path name. For example if your current working directory is /home/tom and if you would like to change directory to /home/tom/docs/bio you can enter command cd docs/bio instead of cd /home/tom/docs/bio .

So you can use a relative path name as a shortcut to the location of files and directories.

Relative pathname example

To refer to a file in a subdirectory of the current working directory, use the name of the subdirectory followed by a slash (/) and the name of the file. For example, to display a file called foo.text in a subdirectory called bar that is located in the current directory /home/tom, enter:
$ pwd
Output:

/home/tom

Now, enter the command:
$ cat bar/foo.txt

.. directory name

To refer to a file in the parent directory of the current directory, use "../" followed by the name of the file. For example,if you are in /home/tom/bar and would like to display /home/tom/file.txt use pathnane ../file.txt:
$ pwd
Output:

/home/tom/bar

Now, enter the command:
$ cat ../file.txt

Home-relative pathname with tilde (~)

The tilde character (~) can be used to refer to your home directory, For example, the pathname ~/file.txt refers to a file named file.txt in your home directory /home/tom/file.txt.
$ pwd
Output:

/tmp

Now, enter the command:
$ cat ~/file.txt

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.