1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

Introduction to Linux

By Machtelt Garrels

Businesswoman working on computer in a modern office
AMV Photo/Digital Vision/Getty Images

3.2.2. Absolute and relative paths

A path, which is the way you need to follow in the tree structure to reach a given file, can be described as starting from the trunk of the tree (the / or root directory). In that case, the path starts with a slash and is called an absolute path, since there can be no mistake: only one file on the system can comply.

In the other case, the path doesn't start with a slash and confusion is possible between ~/bin/wc (in the user's home directory) and bin/wc in /usr , from the previous example. Paths that don't start with a slash are always relative.

In relative paths we also use the . and .. indications for the current and the parent directory. A couple of practical examples:

  • When you want to compile source code, the installation documentation often instructs you to run the command ./configure , which runs the configure program located in the current directory (that came with the new code), as opposed to running another configure program elsewhere on the system.

  • In HTML files, relative paths are often used to make a set of pages easily movable to another place:


       

     
    <img alt="Garden with trees" src="../images/garden.jpg">
     

  • Notice the difference one more time:


       

     
    theo:~> ls /mp3
     ls: /mp3: No such file or directory
     theo:~>ls mp3/
     oriental/ pop/ sixties/
     

* License

* Introduction to Linux Index

  1. About.com
  2. Technology
  3. Linux

©2014 About.com. All rights reserved.