查看inode相关信息

inode定义

The inode (index node) is a data structure in a Unix-style file system 
that describes a file-system object such as a file or a directory. 
Each inode stores the attributes and disk block locations of the object's data.
File-system object attributes may include metadata (times of last change,[2] access, modification), 
as well as owner and permission data.[3]

from inode wiki

inode数据结构用于描述文件系统中的文件、目录等, 每一个inode保存了文件系统系统对象memdata如修改时间,访问时间以及权限等。Dennis Ritchie对于inodei可能代表index,而被访问的文件列表,被组织为存放存放在磁盘上的一维数组。

环境准备

Linux Distributions: CentOS 7

通过fdisk划出一个10M分区, 格式化为ext4

$ fdisk /dev/sdb
...
#         Start          End    Size  Type            Name
 1         2048      8390655      4G  Linux filesyste
 2      8390656      8411135     10M  Linux filesyste
[root@centosgpt ~]#

$ mkfs.ext4 /dev/sdb2
$ mount /dev/sdb2 /root/inode

inode查看

ls

ls -i 文件名or目录

参数为目录的话,会显示出所有文件inode编号

$ echo hello world > text.txt
$ ls -i test.txt
34942335 text.txt

debugfs

针对ext2/ext3/ext4

$echo hello world > text.txt
$sudo debugfs -R "stat text.txt" /dev/sdb2
debugfs 1.42.9 (28-Dec-2013)
Inode: 12   Type: regular    Mode:  0644   Flags: 0x80000
Generation: 816803252    Version: 0x00000001
User:     0   Group:     0   Size: 12
File ACL: 1444    Directory ACL: 0
Links: 1   Blockcount: 4
Fragment:  Address: 0    Number: 0    Size: 0
ctime: 0x5f59c034 -- Thu Sep 10 13:57:08 2020
atime: 0x5f59c034 -- Thu Sep 10 13:57:08 2020
mtime: 0x5f59c034 -- Thu Sep 10 13:57:08 2020
EXTENTS:
(0):8705

stat

$ stat text.txt
  File: text.txt
  Size: 12              Blocks: 4          IO Block: 1024   regular file
Device: 812h/2066d      Inode: 12          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:unlabeled_t:s0
Access: 2020-09-10 13:57:08.000000000 +0800
Modify: 2020-09-10 13:57:08.000000000 +0800
Change: 2020-09-10 13:57:08.000000000 +0800
 Birth: -

参考及引用

Everything You Ever Wanted to Know About inodes on Linux
理解inode
EXT4文件系统的磁盘整体布局

Be First to Comment

发表回复