The difference between a soft connection and a hard link

Source: Internet
Author: User

Objective:

Today, I learned the file system, which is a simple approach to the principle of file system composition. It turns out that we don't delete a file on Linux and win just delete a link. Linux, in turn, divides links into soft links and hard links. Next, we will explain the difference between Linux soft link and hard link from the basic principle of file system composition.

File System Brief:

The philosophy of Linux is all documents. To make it easier for people to use, we can distinguish different files by looking at the file name. But as a machine that only recognizes 0 1, it is certainly more complex to recognize a string of words. So the Linux file system uses a string of numbers to identify a file, and that number is unique in the partition where the file is located. This number is the inode number. What is the inode? The file consists of two pieces of data, namely metadata (metadata) and data. Data is the data we yearn for in the file, and the metadata is something that is not related to the contents of the file but is necessary to manage the file or manipulate the file. For example: File size, file permissions and so on. We store the data in a prescribed place in a file system (this content is further understood in detail in the file system), storing the metadata in a local area called Inode. Full name index node (index nodes). The inode also saves the metadata that contains the location of the file data. This is why the system can find files through the inode number.

The previous article has mentioned that we can see the file name only for the convenience of ourselves, and the Linux system does not use the file name, the inode number is used to identify the file. We keep the files in the directory. The structure of the catalog file is very simple, which is a list of items. Each directory entry consists of two parts: the file name of the included file, and the inode number that corresponds to the file name. Be sure to understand the nature of the catalogue. This is beneficial to understand the following directory read, write, execute permissions. Now we can say that the user opens the file through the filename and what happened. In fact, this process in the system is divided into three steps, first, the system through the corresponding items in the directory file to find the inode number corresponding to the file name, and secondly, through the Inode number to obtain the inode information, finally, according to the Inode information, find out what the file data in the location, read data.

Hard Links:

Although the file contains metadata and data. But this two data is not stored together. Divide two specialized areas, one region (inode) to save metadata, and one region to save the data. If an inode number corresponds to more than one file name, the files are called hard links. In other words, a hard link is the same file that uses multiple aliases, which point to the same file with a different name. Because the inode number is unique only in this partition, hard links cannot span partitions, and hard links cannot point to a directory file. The metadata also holds the number of hard links in the file, and when we delete a hard link, the number of hard links in the file is reduced by one, and when the number of hard links is zero, the space occupied by the file is freed. The file release is simply not a link to the data. The data itself still exists on the disk. So we typically delete a file by simply deleting a link to the file.

Soft connection:

Hard links have limitations of their own, such as: they cannot be created across partitions and cannot be created on a directory. Soft links are inherently free of problems, and a soft connection is a separate file that has an inode number that differs from the linked file, and that the soft link points to not the file's data, but only to the file name, which does not care what the contents of the file are. Therefore, the soft connection will have invalid links, that is, the linked file is not found. Because the inode occupies disk space, the soft-connect file itself is file-sized and consumes an inode number, which itself is a limited resource.


This article is from the "mechanism of small Wind" blog, please be sure to keep this source http://xiaofengfeng.blog.51cto.com/8193303/1870404

The difference between a soft connection and a hard link

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.