4

Each file has an inode. Is there an inode for every directory ? If not, how does Linux manage directories.

11

Directories are special files, hence they have inodes.

You can test that with ls:

ls -li

or using stat:

stat -c '%F : %i : %n' *

Example:

% stat -c '%F : %i : %n' *
regular file : 670637 : bar.csv
regular file : 656301 : file.txt
directory : 729178 : foobar

The number in the middle is the inode number.

  • 5
    It's Unix(like) - Everything is a file! - en.wikipedia.org/wiki/Everything_is_a_file – EightBitTony Jan 13 '16 at 11:32
  • ls -lid maybe? – Jeff Schaller Jan 13 '16 at 12:12
  • @JeffSchaller Yeah..mentioned that already (just not with -d).. – heemayl Jan 13 '16 at 13:01
  • 1
    Most filesystems do implement directories using a special file for each directory (and thus, an inode), but some don't; HFS+ puts the entire name hierarchy in one big B-tree, for instance. – zwol Jan 13 '16 at 18:18
2

Yes, it is.
Use stat *directory name* in order to obtain inode number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.