0

Sorry if this is a stupid question, I am confused by the concept of an inode.

Say I have a file.dat nested in a multi-level directory structure like this:

  folder_1 ->
     folder_2->
        folder_3->
          file.dat

How many inode(s) does this file take up in the filesystem? Is it one (1 inode per file?) or 4 (including the folders?)

Commonboy
  • 41
  • 2
  • 6
  • 2
    Seems more appropriate for unix.stackexchange.com, it's not a programming question. – Barmar May 15 '13 at 23:31
  • Every directory itself has one inode and every file has one inode. There are links to file list in directory inode; and in file inode there are links to data of the file. `ls -li` shows you inode number for every element. – osgx May 15 '13 at 23:34

2 Answers2

4

Each directory is a special kind of file and has an inode of its own, and file.dat has its own inode. The inodes used by the directories are not generally counted when counting the inodes used by a file, since the same inodes are used for all the files in that directory. So if you add file2.dat to folder_3, it only uses up 1 more inode, not another 4.

Barmar
  • 741,623
  • 53
  • 500
  • 612
0

One.

Check out Inode in wikipedia.

A file's inode number can be found using the ls -i command. The ls -i command prints the i-node number in the first column of the report.

albusshin
  • 3,930
  • 3
  • 29
  • 57