2

I know that the filename is stored in directories and not in inode. Kindly tell me where the inode number of a file is stored? Is it stored in the directory file?

Khaled
  • 36,533
  • 8
  • 72
  • 99
LinuxPenseur
  • 443
  • 1
  • 6
  • 16

3 Answers3

4

Yes, directory entries contain the filenames and their inodes.

jlliagre
  • 8,861
  • 18
  • 36
  • Thanks jlliagre. So when I give `ls -il`, the inode numbers are listed from the directory file right? – LinuxPenseur Dec 15 '10 at 08:18
  • Indeed, that's where they live. – jlliagre Dec 15 '10 at 09:17
  • Thanks, Only when i give `ls -l` can i see the inode number. Since directory is also a file, is there any way to see the contents of directory which will list the inode numbers also – LinuxPenseur Dec 15 '10 at 10:24
  • Your statement "a directory is also a file" is dubious. A directory is a directory, not a regular file. Depending on the operation system and the filesystem used, you might or might not be able to see the raw content of the directory. You can try "od -c directory". – jlliagre Dec 15 '10 at 10:37
  • @jlliagre, I am sorry, but i will have to disagree with you on your comment on ""a directory is also a file" is dubious". As far as my knowledge goes `Directories: files that are lists of other files`. So i guess Directory is also a file – LinuxPenseur Dec 15 '10 at 10:51
  • Directories are indeed files in the sense they appear in the filesystem tree but they aren't regular files. Just like devices, symlinks, named pipes, sockets and other exotic entries aren't regular files. – jlliagre Dec 15 '10 at 11:43
  • `ls -i` lists a directory's contents and inode numbers – user9517 Dec 15 '10 at 13:15
1

Inode Structure image is provided below: ss of inode structure

See from the above image. The contents of directory contains inode numbers. Each inode is the index to the inode table. The inode table is stored in the logic disk block. Each entry of inode table stores some file attributes, such as file size, permission, ownership, disk block address, time of last modification etc.

Both directories and ordinary (non-directory) files are files. This definition could be found on Chapter 4, "Modern Operating system", Prof. Andrew S. Tanenbaum.

Further information on inodes can be found here: http://140.120.7.20/LinuxKernel/LinuxKernel/node17.html

slm
  • 7,615
  • 16
  • 56
  • 76
henry
  • 11
  • 2
  • Can you switch those links out with ones from a more permanent website? (i.e. something with a DNS entry) I was going to edit the image into your answer, but we try to avoid links that are likely to break within the year. – Andrew B Apr 07 '13 at 04:15
  • @AndrewB I don't find a new link with a DNS entry for this web. Sorry for that. Thanks for adding the picture. :-) – henry Apr 17 '13 at 13:51
0

According to me, INODE will also use a very tiny portion of disk space (1 or 2 sectors), depends on the size of a file information it holds. In Linux, Inodes will be created when we create the filesystem itself. During that time, a small portion of disk space will be taken for Inodes.

user9517
  • 115,471
  • 20
  • 215
  • 297
Ashok
  • 11
  • 3
    "In Linux, Inodes will be created when we create the filesystem itself." - that depends on the filesystem. The traditional ext[234] filesystems do have fixed inode table, but for example ReiserFS and XFS has dynamic inodes. – Janne Pikkarainen Jul 25 '11 at 10:32