Linux/UNIX的文件系统中,iNode保存了文件的元数据,包括:
- 文件的字节数
- 文件拥有者的User ID
- 文件的Group ID
- 文件的读、写、执行权限
- 文件的时间戳,共有三个:ctime指inode上一次变动的时间,mtime指文件内容上一次变动的时间,atime指文件上一次打开的时间。
- 链接数,即有多少文件名指向这个inode
- 文件内容的block的地址
查看某文件的iNode:
[oracle@odilab ~]$ stat 1.txt
File: `1.txt'
Size: 950782 Blocks: 1864 IO Block: 4096 regular file
Device: fc00h/64512d Inode: 1441745 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 500/ oracle) Gid: ( 503/oinstall)
Access: 2014-01-13 04:36:19.151128601 -0500
Modify: 2014-01-13 04:36:15.505665285 -0500
Change: 2014-01-13 04:36:15.505665285 -0500
目录也是一种文件,如
[oracle@odilab tt]$ vi .
" ============================================================================
" Netrw Directory Listing (netrw v134)
" /home/oracle/tt
" Sorted by name
" Sort sequence: [\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Quick Help: <F1>:help -:go up dir D:delete R:rename s:sort-by x:exec
" ============================================================================
../
t1/
1.txt
3.txt
4.zip
[oracle@odilab ~]$ ls -i tt
1442453 1.txt 1442447 3.txt 1442465 4.zip 1708152 t1
这时我们得到tt目录下所有文件的iNode号和文件名。
Linux/UNIX文件系统分成两个部分:数据区和iNode区(iNode table)。通过df -i 可以查看系统中inode的统计信息:
[oracle@odilab ~]$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/vg_odilab-lv_root
2338336 175013 2163323 8% /
tmpfs 765445 5 765440 1% /dev/shm
/dev/sda1 128016 44 127972 1% /boot
Download 1000 0 1000 0% /media/sf_Download
/dev/sr0 0 0 0 - /media/VBOXADDITIONS_4.2.16_86992
查看
iNode的大小:
[oracle@odilab ~]$ sudo dumpe2fs -h /dev/sda1 | grep -i "inode size"
dumpe2fs 1.41.12 (17-May-2010)
Inode size: 128
Superblock
A superblock is a record of the characteristics of a filesystem, including its size, the block size, the empty and the filled blocks and their respective counts, the size and location of the inode tables, the disk block map and usage information, and the size of the block groups.iNode号:
Linux/UNIX内部用iNode号来访问文件,文件名可以理解为一个别名。因而,每次文件操作,文件系统必须先获取iNode号,然后根据iNode中的block 地址来存取。
[oracle@odilab ~]$ ls -i 1.txt
1441745 1.txt
iNode, 硬连接(hard Link),软连接(Symbolic Link)
Hard link --> iNode: File Name = 1: N。 删除某文件,对其他文件没有影响。
Symbolic link --> iNode: File Name = N: 1。 删除某文件,其他文件也会消失。iNode会被回收。
ln: 创建硬连接
ln -s 创建软连接