Inode is a very important knowledge point of Linux, understanding it is conducive to our further understanding of Linux system.
Today, I happened to see a blog note made by Ruan Yifeng on inode. Here I simply record what I have learned.
Sector, 512 bytes (equivalent to 0.5kb)
A block is composed of eight sectors
File storage is divided into two parts
File meta information
File meta information is inode
The metadata of inode file includes the following contents:
The number of bytes in the file
The user ID of the file owner
The group ID of the file
Read, write and execute permissions of files
There are three timestamps for a file: CTime refers to the time when the inode was last changed, mtime refers to the time when the file content was last changed, and atime refers to the time when the file was last opened.
The number of links, that is, how many file names point to this inode
Location of file data block
View inode information
View the total number of inodes and the number of used hard disks
Each file will have an inode number, which is equivalent to the table ID in the MySQL database and is used to find data. Each file name corresponds to an inode number. When we open a file, we actually go through the following steps:
Find the corresponding inode number through the file name
Obtaining inode information through inode number
Find the block where the data is located through the inode information and read the data
View the inode number of the file / directory
ls -i 1.txt
Due to the separation of inode number and file name, this mechanism leads to some unique phenomena in UNIX / Linux system.
1. Sometimes, the file name contains special characters and cannot be deleted normally. At this time, deleting the inode node directly can delete the file.
2. Moving or renaming a file only changes the file name and does not affect the inode number.
3. After opening a file, the system identifies the file by inode number, regardless of the file name. Therefore, generally speaking, the system cannot know the file name from the inode number.
The third point makes it easy to update the software. It can be updated without shutting down the software. Because the system through the inode number, identify the running file, not through the file name. When updating, the new version of the file will generate a new inode with the same file name, which will not affect the running file. The next time you run the software, the file name will automatically point to the new version of the file, and the inode of the old version will be recycled.
The end of the article
Adhere to learn a little every day, knowledge needs to accumulate, come on ~ share with you~
This work adoptsCC agreementReprint must indicate the author and the link of this article