Detailed explanation of linux index node inode

1 Introduction to inodes     

To understand inode, start with file storage.     

Files are stored on the hard disk, and the smallest storage unit of the hard disk is called a "sector". Each sector stores 512 bytes (equivalent to 0.5KB).      

When the operating system reads the hard disk, it does not read sector by sector, which is too inefficient. Instead, it continuously reads multiple sectors at one time, that is, reads one "block" at a time. This "block" composed of multiple sectors is the smallest unit of file access. The size of the "block", the most common is 4KB, that is, eight consecutive sectors form a block.      

File data is stored in "chunks", so obviously, we also have to find a place to store the meta information of the file, such as the creator of the file, the date the file was created, the size of the file, and so on. This area of ​​storing file metadata is called inode, which is translated as "index node" in Chinese. 

2 inode content     

The inode contains meta information about the file, specifically the following:     

* number of bytes of the file     

* User ID of the file owner    

* Group ID of the file     

* File read, write and execute permissions     

* There are three timestamps of the file: ctime refers to the time when the inode was last changed, mtime refers to the time when the content of the file 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     

* The location of the file data block      

You can use the stat command to view the inode information of a file: [plain] view plain copy [root@localhost /]# stat example.txt In short, all file information except the file name exists in the inode. As for why there is no file name, there will be a detailed explanation below. 

3 inode size     

Inodes also consume hard disk space, so when the hard disk is formatted, the operating system automatically divides the hard disk into two areas. One is the data area, which stores file data; the other is the inode area (inode table), which stores the information contained in the inode.     

The size of each inode node is generally 128 bytes or 256 bytes. The total number of inode nodes is given during formatting, generally an inode is set every 1KB or every 2KB. Assuming that in a 1GB hard disk, the size of each inode node is 128 bytes, and an inode is set every 1KB, then the size of the inode table will reach 128MB, accounting for 12.8% of the entire hard disk.      

To view the total number of inodes and the number of used inodes for each hard disk partition, you can use the df command.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325549380&siteId=291194637