Difference between absolute and relative paths in Linux

0
1288

Absolute Pathnames

An absolute pathname begins with a slash (/). The Absolute path defines the location of a Directory or a file from the root file system (/). The absolute path contains the full path to the directory or file.

Examples of Absolute Path

/usr/share/doc    (Absolute path for a Directory)
/usr/share/doc/bash/README (Absolute path for a Directory)

Question : List the directory which contains all docs by using Absolute path.
Answer: # ls /usr/share/doc/

Relative Pathnames

The relative pathname do not begin with /. It specify the location relative to your current working directory.
Below are some examples of relative pathnames, relative to particular directories.

Current Directory                     Relative Pathname

/usr/shar/doc/HTML/                       index.html
/                                                    usr/share/doc/HTML/index.html
/usr                                               share/doc/HTML/index.html

You can Face one question in your Technical Interview from this topic..i.e What is difference between absolute & relative pathnames in Linux?

SHARE

LEAVE A REPLY