Directories

Features of a directory

A directory is a particular file: it is a two-column array. The first column contains the file names, the second contains their i-node number.

So to designate a file outside its directory, it is necessary to designate the directory in which it finds its name and then this name. Since a directory is a particular type of file, it is sufficient to designate a directory to designate the directory in which the name of the directory is located, then its name, and so on.

The origin of the designation string is a directory called the root of the file system. This is the only directory known directly by the system. Its i-node number is always 2.

The set of directories and files constitutes a tree for which the directories are branches and files the leaves.

We speak of the absolute name of a file when we designate the name of a file by its path from the root.

For example: /home/toto/f1 means the file f1 contained in the toto directory itself contained in the home directory contained in the root directory (the root is designated by /).

Each directory contains two special entries by default: . And ..

  • . Designates the directory itself (or // current // directory)

  • .. designates the // parent // directory

Examples

/:

directory inode name inode
2 .. 0
. 2
35 usr
40 etc

usr:

directory inode name inode
35 .. 2
. 35
bin 54
local 55

etc:

directory inode name inode
40 .. 2
. 40
passwd 41

bin:

directory inode name inode
54 .. 35
. 54
echo 75
cat 189

Thus, the command cat has an absolute path /usr/bin/cat.

When using shell (shell), one can either designate a file by its absolute path, or by a relative path from the current directory. At all times, the user issues his commands from a current directory (the default directory is called home or home directory). Any file can be designated relative to its current directory.

For example, if you are located in the directory /home/toto, the file /usr/bin/cat can also be referred to as ../../usr/bin/cat.