Linux中的所有内容都被视为保持一致性的文件。这包括硬件设备、打印机、目录和进程。诸如音乐、文本、视频和其他多媒体文件之类的常规文件还具有与之关联的附加数据,称为元数据。
Linux中的(Linux)Inode(Inodes)是什么?Inode条目是Linux 文件系统(Linux file system)的基础。它们管理有关文件的元数据,并且是Linux(Linux)内部工作的重要组成部分。
文件系统的结构是什么?(What Is The Structure Of a File System?)
文件系统分为两部分——数据块和索引节点。块数一经创建就固定,不能更改。
名称、路径、位置、链接和其他文件属性不在目录中。目录是简单的表,其中包含具有匹配 inode 编号的文件的名称。
您可以创建一个硬链接,从而为同一个文件生成多个名称。当您创建硬链接时,它还会在带有 inode 的表中创建一个新名称,但不会移动文件。
如果要移动大文件,则需要很长时间。在新目录中创建名称条目并删除旧条目更有效。您也可以以相同的方式重命名文件。
层次结构的顶部是文件系统本身。在文件系统中是文件名。文件名链接到 inode。inode 链接到物理数据。
Linux 中的 inode 是什么?(What Are Inodes In Linux?)
索引节点是一种数据结构。它定义了文件系统上的一个文件或一个目录,并存储在目录条目中。索引节点指向组成文件的块。inode 包含读取文件所需的所有管理数据。每个(Every)文件的元数据(metadata)都存储在表结构的 inode 中。
当使用通过名称引用文件的程序时,系统会在其存在的目录项文件中查找相应的inode。这为您的系统提供了执行流程或操作所需的文件数据和信息。
索引节点通常位于分区的开头(beginning of a partition)附近。它们存储与文件关联的所有信息,但文件名和实际数据除外。任何Linux目录中的所有文件都有一个文件名和一个 inode 编号。用户可以通过引用 inode 编号来检索文件的元数据。
文件(File)名和 inode 编号存储在单独的索引中并链接到 inode。您可以链接到表示文件的元数据。如下图所示,可以有多个文件名链接到一个数据或 inode。
什么是 inode 号?(What Is The Inode Number?)
Linux结构中的每个 inode都有一个唯一的编号。它也称为索引号,具有以下属性:
- 尺寸
- 所有者
- 约会时间
- 权限和访问控制
- 磁盘上的位置
- 文件类型
- 链接数
- 有关文件的其他元数据
要检查 inode 编号列表,请使用以下命令:
ls -i
下面的屏幕截图显示了一个目录,其中 inode 编号出现在最左侧的列中。
索引节点如何工作?(How Do Inodes Work?)
当您创建一个新文件时,它会被分配一个文件名和 inode 号。两者都作为条目存储在目录中。运行 ls 命令(ls -li ) 将显示存储在目录中的文件名和 inode 编号的列表。
使用以下命令列出每个文件系统的 inode 信息。
df-hi
您使用了多少个 inode?
文件系统空间不足的一种方法是用尽所有 inode。即使您的磁盘上有足够的可用空间,您也无法创建新文件。
用完所有 inode 也会导致系统突然停止。要查看有关 inode 使用情况的统计信息列表,例如已使用、空闲和已使用百分比,请键入以下命令:
须藤 df -ih(sudo df -ih)
使用索引节点的其他方式(Additional Ways Inodes Are Used)
inode 在Linux中的工作方式使得 inode 编号不可能出现冲突。不可能在不同的文件系统之间创建硬链接。但是,您可以跨不同的文件系统使用软链接。您可以删除原始文件,但仍然可以通过硬链接获得数据。
通过删除文件,您所做的只是删除指向特定 inode 编号的名称之一。数据将一直保留,直到您删除与同一 inode 编号关联的所有名称。由于 inode 的工作方式, Linux(Linux)系统无需重新启动系统即可更新。
一个进程可以同时使用一个库文件,同时另一个进程用更新的更新版本替换同一个文件并创建一个新的 inode。正在运行的进程继续使用旧文件。下次您使用相同的过程时,它将使用新版本。
用户不直接与 inode 交互,但它们确实代表了Linux文件结构的基本组件。
What Are Inodes in Linux and How Are They Used?
Everything in Linux is considered a file to maintain consistency. Thаt includes hardware devices, printers, directories, and processes. Regular files such as music, tеxt, videos, and other multimedia files also have additіonal data assоciated with them сalled metadata.
What are Inodes in Linux? Inode entries are the basis of the Linux file system. They manage the metadata about a file and are essential pieces of the inner workings of Linux.
What Is The Structure Of a File System?
A file system is divided into two parts – data blocks and inodes. The number of blocks is fixed once created, and can’t be changed.
The name, path, location, links and other file attributes are not located in the directory. Directories are simply tables that contain the names of the files with the matching inode number.
You can create a hard link resulting in more than one name for the same file. When you create a hard link, it also creates a new name in the table with the inode but doesn’t move the file.
If you were to move a large file, it would take a long time. It’s more efficient to create the name entry in a new directory and delete the old entry. You can also rename files in the same way.
The top part of the hierarchy is the file system itself. Within the file system are the file names. The file names link to the inodes. The inodes link to the physical data.
What Are Inodes In Linux?
An inode is a data structure. It defines a file or a directory on the file system and is stored in the directory entry. Inodes point to blocks that make up a file. The inode contains all the administrative data needed to read a file. Every file’s metadata is stored in inodes in a table structure.
When using a program that refers to a file by name, the system will look in the directory entry file where it exists to pull up the corresponding inode. This gives your system the file data and information it needs to perform processes or operations.
Inodes are usually located near the beginning of a partition. They store all the information associated with a file except the file name and the actual data. All files in any Linux directory have a filename and an inode number. Users can retrieve the metadata for a file by referencing the inode number.
File names and inode numbers are stored in a separate index and link to the inode. You can link to the metadata that represents the file. It is possible to have multiple file names that link to one piece of data or inode as you can see in the image below.
What Is The Inode Number?
Every inode in the Linux structure has a unique number identified with it. It is also called the index number and has the following attributes:
- Size
- Owner
- Date/time
- Permissions and access control
- Location on the disk
- File types
- Number of links
- Additional metadata about the file
To check the list of inode numbers, use the following command:
ls -i
The screenshot below shows a directory with inode numbers appearing in the far-left column.
How Do Inodes Work?
When you create a new file, it is assigned a file name and inode number. Both are stored as entries in a directory. Running the ls command (ls -li) will show you a list of the file names and inode numbers that are stored in a directory.
Use the command below to list inode information for each file system.
df -hi
How Many Inodes Are You Using?
One way to run out of space in a filesystem is to use up all your inodes. Even if you have enough free space on your disk, you won’t be able to create new files.
Using up all the inodes can also result in your system suddenly stopping. To see a list of statistics about inode usage such as used, free, and percentage used, type the following command:
sudo df -ih
Additional Ways Inodes Are Used
The way inodes work in Linux make it impossible to have conflicting inode numbers. It is not possible to create a hard link across different file systems. However, you can use soft links across different file systems. You can delete the original files and still have the data available through a hard link.
By deleting a file, all you have done is remove one of the names pointing to a specific inode number. The data will remain until you delete all names associated with the same inode number. Linux systems update without requiring a system reboot in large part because of the way inodes work.
A process can use a library file at the same time another process replaces the same file with a newer updated version and creates a new inode. The running process keeps using the old file. The next time you use the same process, it will use the new version.
Users don’t interact directly with inodes, but they do represent a fundamental component of Linux file structures.