Sunday, April 30, 2017

Oracle Linux - Short Tip 7 - find inode number of file

Everything Linux is storing as a file is done based upon a model that makes use of inodes. The inode is a data structure in a Unix-style file system that describes a filesystem object such as a file or a directory. Each inode stores the attributes and disk block location(s) of the object's data. Filesystem object attributes may include metadata (times of last change, access, modification), as well as owner and permission data. In some cases it can be very convenient to know what the inode ID is for a specific file. you can find the inode number by using the ls command or the stat command as an example.

below you can see the ls command where we extend the ls -l with i to esure we have the inode information we need.

[vagrant@ce log]$ ls -li
total 128
1835019 -rw-r--r--  1 root root   1694 Apr 19 12:04 boot.log
1835122 -rw-------  1 root utmp      0 Apr 19 13:10 btmp
1835323 -rw-------. 1 root utmp      0 Mar 28 10:28 btmp-20170419
1835124 -rw-------  1 root root      0 Apr 28 18:21 cron
1835030 -rw-------  1 root root    250 Apr 19 12:04 cron-20170419
1835108 -rw-------  1 root root      0 Apr 19 13:10 cron-20170428
1835015 -rw-r--r--  1 root root  27726 Apr 19 12:04 dmesg
1835022 -rw-r--r--. 1 root root      0 Mar 28 10:28 dmesg.old
1837835 -rw-r--r--. 1 root root      0 Mar 28 10:28 dracut.log
1835316 -rw-r--r--. 1 root root 146292 Apr 30 12:56 lastlog
1970601 drwxr-xr-x. 2 root root   4096 Mar 28 10:28 mail
1835125 -rw-------  1 root root      0 Apr 28 18:21 maillog
1837833 -rw-------. 1 root root    181 Apr 19 12:04 maillog-20170419
1835118 -rw-------  1 root root      0 Apr 19 13:10 maillog-20170428
1835126 -rw-------  1 root root    789 Apr 30 12:54 messages
1837831 -rw-------. 1 root root  38625 Apr 19 13:10 messages-20170419
1835119 -rw-------  1 root root   5362 Apr 28 18:17 messages-20170428
1837825 drwxr-xr-x. 2 ntp  ntp    4096 Feb  6 05:58 ntpstats
1835130 -rw-------  1 root root      0 Apr 28 18:21 secure
1837832 -rw-------. 1 root root   6740 Apr 19 12:20 secure-20170419
1835120 -rw-------  1 root root      0 Apr 19 13:10 secure-20170428
1835131 -rw-------  1 root root      0 Apr 28 18:21 spooler
1835031 -rw-------  1 root root      0 Apr 19 12:04 spooler-20170419
1835121 -rw-------  1 root root      0 Apr 19 13:10 spooler-20170428
1835302 -rw-------. 1 root root      0 Mar 28 10:28 tallylog
1835128 -rw-r--r--. 1 root root      0 Mar 28 10:28 vboxadd-install.log
1835129 -rw-r--r--. 1 root root     73 Apr 19 12:04 vboxadd-install-x11.log
1835057 -rw-r--r--. 1 root root      0 Mar 28 10:28 VBoxGuestAdditions.log
1835321 -rw-rw-r--. 1 root utmp   6912 Apr 30 12:56 wtmp
1835028 -rw-------. 1 root root     64 Apr 19 12:13 yum.log
[vagrant@ce log]$

Another example of how to get the inode number is by using the stat command. The below example shows how we use stat on the boot.log file in Oracle Linux to get the inode number and other information.

[vagrant@ce log]$ stat /var/log/boot.log 
  File: `/var/log/boot.log'
  Size: 1694       Blocks: 8          IO Block: 4096   regular file
Device: fb01h/64257d Inode: 1835019     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-04-19 12:04:01.517000000 +0000
Modify: 2017-04-19 12:04:05.524262651 +0000
Change: 2017-04-19 12:04:05.524262651 +0000
[vagrant@ce log]$

No comments: