Linux / Unix: Find Inode Of a File Command

last updated in Categories

How do I find out an inode (index-node) of a file under Unix like operating systems?

An inode number stores all the information about a regular file, directory, or other file system object, except its data and name. To find an inode, either use the ls or stat command.


ls Command: Display Inode

$ ls -li filename
$ ls -li /etc/resolv.conf

Sample outputs:
25766494 -rwxr-xr-x 1 root root 332 May 5 14:14 /etc/resolv.conf
25766494 is inode number and the -i option displays the index number (inode) of /etc/resolv.conf file.

stat Command: Display Inode

You can also use the stat command as follows:
$ stat fileName-Here
$ stat /etc/passwd

Sample outputs:

  File: `/etc/passwd'
  Size: 1644      	Blocks: 8          IO Block: 4096   regular file
Device: fe01h/65025d	Inode: 25766495    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-05-05 16:29:42.000000000 +0530
Modify: 2012-05-05 16:29:20.000000000 +0530
Change: 2012-05-05 16:29:21.000000000 +0530


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

5 comment

  1. Everything has its pros and cons.Unix came first. Linux was born from it. UNIX: used for really big sytmess. more stable. good for doing standard things or old internet things.LINUX: more toys. tends to be prettier. popular for personal servers and desktop machines. good for doing newly thought of things on the netThink of Unix as a semi-truck and Linux as a hot car. Both can be used to haul freight or drive around town but the best choice for each is pretty obvious.

  2. The only time I’ve even needed to know the inode number is if I have a file with some very strange name that prevents me from (easily) using “rm”.

    I get into the parent directory then use (from memory, I haven’t actually had my hands on a unix box in a while) find . -exec ls -i {} \;

    That could be grossly wrong somehow, but I’m sure someone will jump in.

    I can then use “rm” to remove the inode number and not need the file name. Seems to me that I might have had to use that find/exec thing again.

    Still, have a question? Get help on our forum!