If you come from the Windows world, you may not be familiar with the concept of inode. This is not something you are exposed to until you journey into the Unix world.

Even if you use Unix, you may or may not encounter an inode. It depends on how much you care about the systems internals of the Unix world. If you do care, keep reading because it is going to get very interesting.

Inode (index node) is a data structure in a Unix-style file system such as Linux, Solaris, MacOS, and FreeBSD that describes a filesystem object such as a file or directory. Each inode stores the following information

  • Permission such as read, write and execute
  • Owner ID
  • Group ID
  • Size of the file
  • Number of hard link relative to an inode
  • Time of last change
  • Time of last access
  • Time of last modified
  • Link to location of the file

What is stored in a Unix file?

A Unix file is stored in two different parts of the disk – the data blocks and the inodes. The data blocks contain the contents of the file. The information of the file is contained in the inode.

How to check the inode?

To list the inodes of a file, use the “ls -i” command.

$ cd /
$ ls -i
16777217 bin              1048577 lib          5505025 var
       2 boot            54001665 lib64       36175873 sbin
    1025 dev             53870593 media       42860545 srv
42729473 etc             32243713 mnt         58720257 tmp
27525121 home            25690113 opt         

By using the -i option, you can see the inode number before the filename.

Display file system information

Another way to view the inode of a file is by using the stat command. Unlike the previous command, this option gives you information about the times of last changed, accessed and modified of a file.

$ stat hello.txt
  File: hello.txt
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: fe00h/65024d	Inode: 27534469    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  root)   Gid: ( 1000/  root)
Access: 2020-06-04 06:23:12.213401430 -0700
Modify: 2020-06-04 06:20:27.907562714 -0700
Change: 2020-06-04 06:20:27.927563425 -0700
 Birth: -

You also see a lot of other information about the file such as ownership and permissions.

Tim Miller

Tim has always been obsessed with computers his whole life. After working for 25 years in the computer and electronics field, he now enjoys writing about computers to help others. Most of his time is spent in front of his computer or other technology to continue to learn more. He likes to try new things and keep up with the latest industry trends so he can share them with others.

Leave a Comment