Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 11 down vote accepted

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.

share|improve this answer
5  
It's Unix(like) - Everything is a file! - en.wikipedia.org/wiki/Everything_is_a_file – EightBitTony Jan 13 at 11:32
    
ls -lid maybe? – Jeff Schaller Jan 13 at 12:12
    
@JeffSchaller Yeah..mentioned that already (just not with -d).. – heemayl Jan 13 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 at 18:18

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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