How to see information inside inode data structure

16,573

Solution 1

If you have a ext2/3/4 filesystem you can use debugfs for a low-level look at an inode. For example, to play without being root:

$ truncate -s 1M myfile
$ mkfs.ext2 -F myfile
$ debugfs -w myfile
debugfs:  stat <2>
    Inode: 2   Type: directory    Mode:  0755   Flags: 0x0
    Generation: 0    Version: 0x00000000
    User:     0   Group:     0   Size: 1024
    File ACL: 0    Directory ACL: 0
    Links: 3   Blockcount: 2
    Fragment:  Address: 0    Number: 0    Size: 0
    ctime: 0x5722081d -- Thu Apr 28 14:54:53 2016
    atime: 0x5722081d -- Thu Apr 28 14:54:53 2016
    mtime: 0x5722081d -- Thu Apr 28 14:54:53 2016
    BLOCKS:
    (0):24
    TOTAL: 1

The command stat takes a inode number inside <>.

Solution 2

You can find inode information using stat command.

# stat myfile.txt
  File: myfile.txt
  Size: 2023        Blocks: 8          IO Block: 4096   regular file
Device: fd03h/64771d    Inode: 15997895    Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   antop)   Gid: ( 1000/   antop)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2019-08-30 08:29:16.974661276 +0530
Modify: 2019-08-30 08:29:16.974661276 +0530
Change: 2019-08-30 08:29:16.974661276 +0530
Birth: 2019-08-30 08:29:16.974661276 +0530

a detailed note on inode, hardlink & softlink

Solution 3

an inode wil store only one file. try

find /xxx -xdev -inum 1234 -print

where

  • /xxx is mounting point
  • -inum 1234 search for an inode number 1234
  • -print self explainatory

This suppose /xxx is mounted an healthy.

Share:
16,573

Related videos on Youtube

Ijaz Ahmad
Author by

Ijaz Ahmad

Linux Bash Python Kubernetes ( On-prem, AWS, GKE, DO ) Docker ElasticSearch Gitlab/Github Jenkins DevOps/SRE/Automation/CI/CD Infra as Code, Pulumi, Terraform

Updated on September 18, 2022

Comments

  • Ijaz Ahmad
    Ijaz Ahmad over 1 year

    I can do an ls -li to see a file's inode number, but how can I list information inside a particular inode by using that inode number.

    • Mat
      Mat almost 8 years
      Plain ls -l? What information are you after exactly?
    • Ijaz Ahmad
      Ijaz Ahmad almost 8 years
      Ok i just tried the stat command on the file name , and most of the information an inode contains is reported by stat command
    • wisbucky
      wisbucky almost 5 years
      See this excellent answer: unix.stackexchange.com/questions/216644/…
  • Yuri Pozniak
    Yuri Pozniak almost 3 years
    Not quite what is requested in the question but still was useful in educational purpose. Thanks.