CS 160A - Absolute Paths, Relative Paths, Symbolic Links

Find, Locate (Chapters 4, 5, 17 Shotts)

Absolute Pathnames

"An absolute pathname begins with the root directory and follows the tree branch by branch until the path to the desired directory or file is completed. For example, there is a directory on your system in which most of our system's programs are installed. The pathname of the directory is /usr/bin. This means from the root directory (represented by the leading slash in the pathname) there is a directory called usr which contains a directory called bin."

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)."

Important Facts About Filenames

A File in the Linux System

We can imagine that files are made up of two parts:

When we use ls -l, we are actualy looking at the "name part" of the file, linking to the "data part" of the file's contents.

The system assigns a chain of disk blocks which we call inodes to be associated with each name part.

Symbolic Links

The symbolic link is derived from the hard link. Hard links are the original way of creating links to files. By default, every file has a single hard link that gives the file its name.

Hard links have two important limitations:

We don't use hard links too much in practice, but they are conceptually important.

Symbolic links create a special type of file that contains a text pointer to the referenced file or directory (inspiration for the Windows shortcut).

"A file pointed to by a symbolic link, and the symbolic link itself are largely indistinguishable from one another. For example, if you write something to the symbolic link, the referenced file is written to. However when you delete a symbolic link, only the link is deleted, not the file itself. If the file is deleted before the symbolic link, the link will continue to exist, but will point to nothing. In this case, the link is said to be broken. In many implementations, the ls command will display broken links in a distinguishing color, such as red, to reveal their presence."

Creating a hard link:

ln fileA fileB
ln fileA dir/fileB

When we create a hard link, we are referring to additional name parts that refer to the data part

Each hard link refers to a specific inode containing the file's contents. We can see that more clearly by running ls -li and checking the first column i.e. the inode number.

For more on this material refer to the course textbook: "The Linux Command Line" by Shotts

Creating a symbolic link:

Symbolic links can refer to directories and span across physical devices.

Creating a symbolic links is similar to creating a hard link:

ln -s fileA fileB
ln -s ../fileA dirA/fileB
ln -s ../fileB dirA/fileB

Symbolic links can be created using absolute pathnames or relative pathnames

  1. Deleting a symbolic link does not delete the original link
  2. Deleting the original file results in a broken link

Some more commands to help you navigate file structures

  1. type: Indicate how a command name is interpreted
  2. which: Display which executable program will be executed
  3. info: Display a command's info entry
  4. find
  5. locate