Home > Hosting > Server

What does the i-node number of linux mean?

2023-05-18 14:56:39

This article introduces the knowledge about what the i-node number of linux means. During the operation of the actual case, many people will encounter such a dilemma. Next, let the editor guide you to learn how to deal with it These situations! I hope you read it carefully and learn something!

In linux, the i-node number refers to the inode number, which is used to identify different files. Linux internally uses the inode number to identify the file instead of the file name. For the system, the file name is another name for the inode number, which is convenient for users to identify the file. The file name and the inode number have a one-to-one correspondence, and each inode number corresponds to a filename.

1. The i-node in linux

In linux, the i-node refers to the inode node.

In linux, the file search is not searched by the file name. In fact, the search and location of the file is realized through the i node. We can visualize the i-node as a pointer fip. When the file is stored on the disk, the file will definitely be stored in a disk location. It can be imagined that since the file data is stored on the disk, if we know the address of the file data, when we want to read and write the file At that time, can we just use this address to find the file directly?

Yes, under Linux, the i-node can actually be regarded as such, and the i-node is regarded as an address pointing to the file storage area on the disk. It's just that we generally can't use this address directly, but use it indirectly through the file name. In fact, the i-node not only contains the address of the file data storage area, but also contains a lot of information, such as data size, and other file information. But the i node does not save the file name. The filename is stored in a directory entry. Each directory entry contains the file name and i-node.

We can use a graph to see the relationship between directory items, i-nodes, and file data.

As you can see from the above figure, the directory entry contains the file name and i node.

At the same time, you will find that in the figure above, the i-nodes of directory entry A and directory entry B point to the same storage area, where the data of printf("ha") is stored in this storage area.

It means that the contents of helloA.c and helloB.c are the same.

i node number

Each inode has a number (that is, the inode number), and the operating system uses the inode number to identify different files.

————LinuxThe inode number is used internally to identify the file instead of the file name. For the system, the file name is another name for the inode number, which is convenient for users to identify the file. The file name and the inode number have a one-to-one correspondence, and each inode number corresponds to a file name.

The inode number is the only code recognized by the system, and the file name is only for user identification. The inode (index node) table contains a list of all files in the file system. A node (index node) is in a table Item, containing information (metadata) about the file.

The structure of the hard disk partition:

  • When the user tries to access a file in the Linux system, the system will first follow the file Name to find its corresponding inode number; through the inode number, get the inode information; according to the inode information, see if the user has the permission to access the file; if yes, point to the corresponding data block, and read the data; if not will return.

A simple process for accessing files:

Second, Linux file storage

2.1 Limitation on the number of inodes

  • Inodes will also consume hard disk space, so when formatting, the operating system will automatically divide the hard disk into two Area: One is the data area, which stores file data; the other is the inode area, which stores the information contained in the inode. The size of each inode is generally 128 bytes or 256 bytes.

  • Usually, you don’t need to pay attention to the size of a single inode, but you need to focus on the total number of inodes. The total number of inodes has been set during formatting
    —— Why do we need to focus on the total number of inodes, because When the inodes are used up, even if there is space on the disk, new files cannot be created, because when creating a file, an inode number is needed to correspond to it, and when there is no inode Naturally new files cannot be created.
    Execute the df-i command to view the total number of inodes corresponding to each hard disk partition and the number of used inodes.

2.2 Inode content

Inode contains the meta information of the file, specifically as follows The content of:

  • The number of bytes of the file

  • The user ID of the owner of the file

  • < li>

    g of the fileroup ID

  • File read, write, execute permissions

  • The number of links, that is, how many files point to this inode

  • The time stamp of the file

  • Two ways to view the inode information of a file

Method 1: stat [filename]

Example: stat aa.txt

Advantage: You can view the detailed information of the file inode

Method 2: ls -i [file name]

< p>

Only display the inode number

2.3 Three main time attributes of Linux system files

< p>The three main time attributes of Linux system files (that is, the timestamp in the inode)

  • ctime (change time)
    refers to the last change The time of the file or directory (attribute)

  • atime (access time)
    refers to the last The time of accessing files or directories

  • mtime (modify time)
    refers to the last time modified files or directories ( Content) time

Third, the special role of inode

Because The inode number is separated from the file name, causing some Unix/Linux systems to have the following phenomena:

  • When the file name contains special characters, the file may not be deleted normally, delete it directly Inode, you can also delete files

  • When moving or renaming files, only the file name is changed, and the inode number is not affected

  • After opening a file, the system identifies the file by the inode number, regardless of the file name

  • After the file data is modified and saved, a new inode number will be generated (the original inode number will be freed)

How to delete a file by deleting the inode number:

Method 1 (confirm the information before deleting): find ./ -inum [inode number] -exec rm -i {} ;

Method 2 (delete directly): find ./ -inum [inode number] -delete

The i-node number of linux refers to That's all for now, thank you for reading. If you want to know more industry-related knowledge, you can pay attention to the Yisuyun website, and the editor will output more high-quality practical articles for you!


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us