简体   繁体   中英

Parent directory listing at root directory

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?

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 (/) ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM