Q. How do I display file inode number using command line?
A. An inode is a data structure on a Unix / Linux file system. An inode stores basic information about a regular file, directory, or other file system object. You can use following two commands to display an inode:
[a] ls command : list directory contents
ls command
Type ls command with -i ( print the index number of each file ) option:
$ ls -i /etc/passwd
Output:
752010 /etc/passwd
752010 is index number (inode) for /etc/passwd file.
stat command
$ stat /etc/passwd
Output:
File: `/etc/passwd'
Size: 2026 Blocks: 8 IO Block: 4096 regular file
Device: 811h/2065d Inode: 752010 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2007-08-20 23:19:20.000000000 +0530
Modify: 2007-07-07 00:06:56.000000000 +0530
Change: 2007-07-07 00:06:56.000000000 +0530
You can use inode number to delete or search a file.
🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 2 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Hi, I would like to use grep command on a file by mentioning it’s inode number instead of it’s file name. Does grep command has this facility. If yes, how do I do it?
What I want is some thing along the lines of this: grep PATTERN
Thanks in advance.
What I want is some thing along the lines of this: grep [whatever options] PATTERN [inode no.]. I previously wrote them using “>” and “<" instead of [ and ].