Skip to main content

1.6 The filesystem

The linux filesystem comprises a set of files. A file can be one of three general types;

  • ordinary files - these files contain data
  • special files - e.g. files that control access to the printer
  • directories - these contain information about a set of files and are used to locate a file by name

As you might expect, the linux filesystem is organised as a hierarchy of directories. Each directory can contain both files and subdirectories. The very top of this hierarchical tree is known as the root directory. The root directory is always specified under linux as / .

Another important concept in the linux filesystem is the current working directory . The current working directory refers to the directory from which you are located. You can always check where you are in the tree by using the command pwd in your shell.

Putting it into Practice:

You can always check where you are in the tree by typing
  prompt> pwd   
What is your current working directory at the moment?

Files can be located in one of two ways; with a relative path name or an absolute path name .

The absolute path name must contain the sequence of subdirectories that must be traversed, starting at the root directory and working down from there. Because the absolute path name always starts with root, it therefore always begins with a /.

Example:

linux interprets the absolute path name /home/phillipa/output as follows
(1) From the root directory, go to the subdirectory named home
(2) From the subdirectory named home , go to the subdirectory named phillipa
(3) From the subdirectory named phillipa , select the file called output

To use a relative path name you need to know your current working directory . In a relative path name, your current working directory is the start point for your file names. Therefore, a relative path names does not usually start with / (since your current working directory is usually not root).

Example:

Taking the absolute path name from the previous example, if your current working directory is /home/ then the relative path name will be
phillipa/output
The most straightforward case of a relative path name is a single file identifier, that refers to a file in your current working directory.

Example:

Taking the absolute path name from the firsst example, if your current working directory is /home/phillipa/ then the relative path name will be
output
In other words, the relative path name is just the name of the file (in this case, the file is called output ).

Two other notations are very important in linux filesystems - . and ..

To explain- the parent of a directory, say, phillipa/ from our past example, is located just above phillipa/ in the hierarchy. The current directory is named . and the parent directory is named ..

Therefore, you can use path names to go up the tree, as well as down.

Example:

If your current working directory is /home/phillipa/ then the relative path name ../harry/MP3s refers to the absolute path name /home/harry/MP3s

One final useful concept is the home directory . Every user has a home directory . For example, if your username is phillipa , then your home directory will be /home/phillipa

There is a special path name notation for the home directory, which is to use ~ at the start of the path name.

~ at the start of a path name refers to the home directory of the current user. For user phillipa , ~/output refers to /home/phillipa/output , while ~harry/MP3s refers to /home/harry/MP3s

Use this schematic of an example linux filesystem to follow the examples given in this section

.