List of parent directories in the root directory

As we all know. Each Unix directory contains special directories - current (.) And parent (..). Also, the top-level root directory in Unix is ​​called "/".

When I tried in the root directory,

$ ls -ia 2 . 2 .. 3963 bin ............... 

both (.) and (..) have the same inode number

& performance

 $ cd .. 

in the root directory ends in the same place.

My question is, why does even the root directory contain a special list of directories (..)? What is the need to list (..) in the root directory?

+5
source share
2 answers

It just has to contain an agreement .


According to POSIX defintion

3.144 Empty directory

A directory containing, at most, entries in the directory for points and point-to-point, and has exactly one link to it (except for its own entry point, if one exists), in points. This definition is repeated with various phrasings in the POSIX descriptions of all file commands.

From superuser answer :

This is the collapsed definition for the Empty Directory above, apparently behind this funny convention, and its purpose is to avoid any exceptions to the rule, even for a slash (/), i.e. root directory.

+4
source

This is the Unix standard for directories. All directories have an entry for themselves (.), As well as a parent (..). These special entries will be used to traverse the directory. With the β€œkeep it simple” policy, the root directory has the same basic structure as any other directory.

+1
source

Source: https://habr.com/ru/post/1261478/


All Articles