Inode, hard link, and symbolic link)

Source: Internet
Author: User

Index node inode:Linux assigns an index node number to each file. inode can be simply understood as a pointer, which always points to the specific storage location of the file on the physical disk. The system locates each file by indexing nodes (rather than file names.

 

Hard connection:One inode number must correspond to one-to-one data storage area of a file. Can two or more different file names in a file system correspond to the same file? The answer is yes. We know that the inode number is recorded in the directory item corresponding to the file name. We can make the directory items of two or more files have the same inode value, actually, they correspond to the same data storage zone. There are several directory items with the same inode number. We can say that this file has several hard links. For common files, the Count field value of the LS-l command is the number of hard connections in this file. You can use the ln command to create a hard connection. Creating a hard connection actually only adds a directory item, but does not copy the file data zone. The data zone of the original file is shared by two files. In this way, it can save a lot of disk space and ensure that the two files can be updated simultaneously.

# Ln/home/zyd/mytext hardlink_mytext
Ls-il 'can display the inode of the file (at the leftmost of the following ):
262457-RW-r-2 zyd 17 Nov 3 14:50 hardlink_mytext
262457-RW-r-2 zyd 17 Nov 3 14:50 mytext

Connection count:The connection count field indicates that several files share the same data storage zone, that is, several hard connections (hardlink_mytext and mytext are hard connections ). In the preceding example, the Count values of the hardlink_mytext and mytext files are both 2. When you delete a hard connection file, the system first calculates the count-1 value. If the value is greater than 1, only the directory items are deleted and the number of hard connections is modified. If the value is 1, the directory items are deleted, change the number of hard connections of the other file to a normal file. If the value is 0, delete the file directly. We can establish a hard connection to protect important files and avoid accidental deletion.

Symbolic connection:Soft link refers to the file path, which is very similar to the shortcut in windows.

Differences between symbolic connection and hard connection:

A symbolic connection is a path pointing to a file. It does not even need the existence of the original file (this is called a broken link). A hard connection points to the same data zone, which must exist. In addition, hard Connections cannot be established for directories, or cross-file systems.

 

// ================================================ ========================================

 

A Linux orthodox File System (such as ext2 and ext3) consists of directory items, inode, and data blocks.

Directory item: Includes the file name and inode node number.

Inode: Also known as the file index node, it is the place where the basic information of the file is stored and the data block pointer is stored.

Data Block: The location where the file content is stored.

 

Linux orthodox file systems (such as ext2 and 3) partition hard disks into Directory blocks, inode table blocks, and data block data areas. A file consists of a directory item, inode, and data area block. Inode contains file attributes (such as read/write attributes, owner, and pointers to data blocks), and data area blocks are file content. When viewing a file, the system first detects the file attributes and data storage points from the inode table, and then reads data from the data block.

 

Standing in the 2 W view, the file storage structure is roughly as follows:

 

The structure of the Directory items is as follows (the directory items of each file are stored in the file content of the directory to which the file belongs ):



Figure 4: Directory item Structure

 

The inode structure of the file is as follows (the file information contained in the inode can be viewed through STAT filename ):

 

 

Figure 5 inode Structure

The above only reflects the general structure, and the Linux file system itself is evolving. However, the above concepts remain unchanged. There are also many differences in ext2, ext3, and ext4 file systems. For more information, see the introduction of specialized file systems.

5. Soft connection and hard link

Soft links and hard links are two common concepts:

Hard connection: Creates a copy of the file and establishes a connection between the two. Modify one of them, and the connected file is modified at the same time. If you delete any [/color] of the [color = Red] files, the remaining files will not be affected.

Soft connectionIt is also called a symbolic connection. It only creates a "quick (borrow wondows frequently used words)" for the source file at a new location. Therefore, when the source file is deleted, the file connected by the symbol will become a source-> there is only one file name left. Deleting the connection will not affect the source file, but the use and reference of the connection file will directly call the source file.

For details, refer:

 

 

Figure 5: soft and hard links

 

 

 

The differences between hard and soft links are shown in the figure:

1: The inode numbers of the original and new files are the same. The soft link is different.

2: deleting the original file will make the soft link unavailable, but the hard link will not be affected.

3: modify the content of the original file. The content of soft and hard-link files is also modified, because they all point to the same file content.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.