본문 바로가기

카테고리 없음

Understanding Absolute and Relative Paths

Understanding Absolute and Relative Paths

There are two ways to identify paths:

  1. Absolute pathname: An absolute pathname begins with the root directory and follows the tree, branch by branch, until it reaches the desired directory or file. Absolute paths always start with /.
  2. Relative pathname: A relative pathname starts from the present working directory. Relative paths never start with /.

Multiple slashes (/) between directories and files are allowed, but all but one slash between elements in the pathname is ignored by the system. ////usr//bin is valid, but seen as /usr/bin by the system.

Most of the time it is most convenient to use relative paths, which require less typing. Usually you take advantage of the shortcuts provided by: . (present directory), .. (parent directory) and ~ (your home directory).

For example, suppose you are currently working in your home directory and wish to move to the /usr/bin directory. The following two ways will bring you to the same directory from your home directory:

  1. Absolute pathname method: $ cd /usr/bin
  2. Relative pathname method:   $ cd ../../usr/bin

In this case, the absolute pathname method is less typing