Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parent directory listing at root directory

Tags:

linux

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?

like image 398
engineer2014 Avatar asked Dec 19 '16 05:12

engineer2014


People also ask

Is parent directory and root directory same?

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.

What are the directories under the root directory?

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.

What is the value of the parent of the root directory )?

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.


2 Answers

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.

like image 163
Nabeel Ahmed Avatar answered Oct 28 '22 03:10

Nabeel Ahmed


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.

like image 25
codeforester Avatar answered Oct 28 '22 04:10

codeforester