As we all know. Every Unix directories contains special directories- current(.) & parent(..). Also top level root directory in Unix is called " / ".
When I tried at root directory,
$ ls -ia
2 .
2 ..
3963 bin
...............
both (.) & (..) has same inode number
& executing
$ cd ..
at root directory ends at the same location.
My question is why does even root directory contains special directory listing (..)? What is the need to list (..) at root directory?
Refers to the directory above another directory. Every directory, except the root directory, lies beneath another directory. The higher directory is called the parent directory, and the lower directory is called a subdirectory.
This top level, or root directory, is given the name /. An example of a directory system is shown in Figure 35.1. In this case there are 5 sub-directories below the root level, these are bin, usr, etc, dev and user.
The root directory has a '. ' and a '..' entry in it, and the inode number for each is the same. Traditionally, the inode number is 2; it still is on MacOS X, Linux, Solaris.
Simply, it's just there to keep the convention consistent.
According to POSIX defintion
3.144 Empty Directory
A directory that contains, at most, directory entries for dot and dot-dot, and has exactly one link to it (other than its own dot entry, if one exists), in dot-dot. This definition is repeated with different phrasings in the POSIX descriptions of all file-commands.
From Superuser answer:
This above convoluted definition for an Empty Directory is apparently behind this funny convention, and its purpose is to avoid any exceptions to the rule, not even for slash (/) i.e. root dir.
That's the Unix standard for directories. All directories have an entry for themselves (.) as well as the parent (..). These special entries would be used for directory traversal. With the "keep it simple" policy, root directory has the same basic structure like any other directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With