Why does '/' have an '..' entry?

Nathan Osman

This has always puzzled me. Why does the root directory contain a reference to a parent directory?

bob@bob:/$ ls -a
.     build  home            lib32       mnt   .rpmdb   sys  vmlinuz
..    cdrom  initrd.img      lib64       opt   sbin     tmp  vmlinuz.old
bin   dev    initrd.img.old  lost+found  proc  selinux  usr
boot  etc    lib             media       root  srv      var

I understand how directories are managed in the filesystem - each directory has n+2 pointers to itself (n = number of subdirectories inside the directory). One for each immediate subdirectory, one for its parent, and one for itself.

But what is /'s parent?

Warren Young

/.. points to /:

$ ls -id /
2 /
$ ls -id /..
2 /..

Both have the same inode number, which happens to be 2 on this system. (The exact value doesn't matter.)

It's done for consistency. This way, there doesn't have to be code in the kernel to check where it currently is when it processes a .. in a path. You can say cd .. forever, and never go deeper than the root.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

I have a crontab entry that calls a bash script. Why does $USER return blank?

分類Dev

Why does Docker have a daemon?

分類Dev

Will a Stored Proc be consider compiled if it does not have an entry in cache?

分類Dev

Why does C++ not have reflection?

分類Dev

Why does C++ not have reflection?

分類Dev

Why does C++ not have reflection?

分類Dev

Why std::vector does not have a release method?

分類Dev

Why does my viewmodel name have to be 'model'?

分類Dev

Why does the Javascript EventLoop have different result?

分類Dev

Why does __new__ not have classmethod decorator

分類Dev

Why does Windows have multiple Desktop views?

分類Dev

Why does overriding OnPaint() have no noticeable effect?

分類Dev

Why does Chrome have two encoding settings?

分類Dev

Why does npm install say I have unmet dependencies?

分類Dev

Why does pthread_cond_wait have spurious wakeups?

分類Dev

Why does the escape key have a delay in Python curses?

分類Dev

Why does numpy have a corresponding function for many ndarray methods?

分類Dev

Why does AVPlayerView not have a member named "player" in Swift

分類Dev

Why does Rust have both call by value and call by reference?

分類Dev

Why does a Redux reducer have to be side-effect free?

分類Dev

Why does Box<trait> have a different size than Box<struct>?

分類Dev

My Docker container does not have IP address. Why?

分類Dev

Why does std::unordered_map have a reserve method?

分類Dev

Why does the Linux kernel have `struct sock` and `struct socket`?

分類Dev

Why does reverse_iterator have a default constructor?

分類Dev

Why does fundamental matrix have 7 degrees of freedom?

分類Dev

Why does pattern matching on a union have an unreachable pattern warning?

分類Dev

Why does this Task return early? Have I done something wrong?

分類Dev

Why does this Task return early? Have I done something wrong?

Related 関連記事

  1. 1

    I have a crontab entry that calls a bash script. Why does $USER return blank?

  2. 2

    Why does Docker have a daemon?

  3. 3

    Will a Stored Proc be consider compiled if it does not have an entry in cache?

  4. 4

    Why does C++ not have reflection?

  5. 5

    Why does C++ not have reflection?

  6. 6

    Why does C++ not have reflection?

  7. 7

    Why std::vector does not have a release method?

  8. 8

    Why does my viewmodel name have to be 'model'?

  9. 9

    Why does the Javascript EventLoop have different result?

  10. 10

    Why does __new__ not have classmethod decorator

  11. 11

    Why does Windows have multiple Desktop views?

  12. 12

    Why does overriding OnPaint() have no noticeable effect?

  13. 13

    Why does Chrome have two encoding settings?

  14. 14

    Why does npm install say I have unmet dependencies?

  15. 15

    Why does pthread_cond_wait have spurious wakeups?

  16. 16

    Why does the escape key have a delay in Python curses?

  17. 17

    Why does numpy have a corresponding function for many ndarray methods?

  18. 18

    Why does AVPlayerView not have a member named "player" in Swift

  19. 19

    Why does Rust have both call by value and call by reference?

  20. 20

    Why does a Redux reducer have to be side-effect free?

  21. 21

    Why does Box<trait> have a different size than Box<struct>?

  22. 22

    My Docker container does not have IP address. Why?

  23. 23

    Why does std::unordered_map have a reserve method?

  24. 24

    Why does the Linux kernel have `struct sock` and `struct socket`?

  25. 25

    Why does reverse_iterator have a default constructor?

  26. 26

    Why does fundamental matrix have 7 degrees of freedom?

  27. 27

    Why does pattern matching on a union have an unreachable pattern warning?

  28. 28

    Why does this Task return early? Have I done something wrong?

  29. 29

    Why does this Task return early? Have I done something wrong?

ホットタグ

アーカイブ