Soft connections and hard links under Linux systems

Source: Internet
Author: User
Tags install mongodb

The previous few days in the Linux system to install MongoDB, and then run the script to import data when the link library encountered the query is not the case, 1 shows. The problem was solved by creating a soft connection. Although, through the online tutorials to solve the problem, but for soft connections and hard links are always not very clear. Take advantage of the weekend to make up for the lessons, the concept of soft links and hard link, features and create a limited system to learn about.

Figure 1 hints for missing files

There are two types of connection files under Linux, one is a soft connection like a shortcut to Windows, and the other is a hard link that is commonly referred to. Both of these links are available for file sharing. Below according to own understanding to do an introduction, if has the wrong place, welcome everybody to criticize correct.

Before you introduce hard links and soft joins, first describe the Linux system's settings for files. Files are composed of file names and data stored in files, which are divided into two parts on Linux: The User data section and the metadata section. The user data is the file data block, records the real content in the file, the metadata contains the attached properties of the file, such as the size of the file, the time of creation, the owner information, the group to which it belongs. The content of user data in Linux is identified by the inode in the metadata, which means that the inode number is the unique identifier of the file, not the filename. The file name is only for the user's memory and ease of use, users can get the corresponding inode number through the file name, the system or program through the inode number to find the correct file data block, 2 shows.

Figure 2 File System settings

  One, hard links

The next inode in a hard link typically corresponds to more than one file name, which can be created through link or LN, essentially creating a file name that is linked to an inode number under a directory document, as shown in 3. It has the following characteristics:

    1. Hard links have the same inode and data,4;
    2. You can only create a hard link to a file that already exists, not a hard link to a nonexistent file, 5;
    3. You can only create hard links to files, you cannot create hard links to directories, 6;
    4. Since the Linux system stores different file categories under different directory systems, it is not possible to cross-establish hard links to different file file systems, 7;
    5. Because hard links are different files referencing the same inode and data, deleting a hard link does not cause the inode and data to disappear, and the final data is deleted only when all links to this inode are deleted. , which means that different hard links do not affect each other, and this kind of reference is similar to the application of smart pointers;

Figure 3 Hard Links

Figure 4 the same inode with hard links

Figure 5 Creating a link to a nonexistent file

Figure 6 Creating a hard link to a directory fails

Figure 7 Creating a hard link between different devices

  Two, soft connection

Unlike a hard connection, a soft connection typically holds a pointer to the directory name of another file (that is, the path to another file) rather than the Inode value. So the soft connection has its own inode data, and the value of this inod is the same value as the Inode value of the file to which you want to point (if the soft connection and the file you are pointing to have a different file system), 8. Based on the above definition of soft links, you can get a soft link defined as follows:

    1. Soft links have their own meta-data and user data;
    2. You can create a soft link to a nonexistent file, or even create a soft connection to a folder, or if you create a soft link to a nonexistent file, the soft link is eventually called a dead link, and if you later create the file that the soft link points to, the soft link will no longer be a dead link, as shown in 9.
    3. Because the soft link is the path to the user data in another file, if the file being pointed to is deleted, then the link fails, and becomes a dead link, as indicated in red;
    4. Soft links can be created by cross-file system, so the inode of soft links and the inode of the pointed file can have the same value, can be found by finding/-inum xxxx with the same inod worth of files;

Figure 8 Soft Connection

Figure 9 Soft Connection test Case

  Summarize:

  The link mechanism can reduce the duplication of unnecessary files and reduce the pressure on the disk.

Soft connections and hard links under Linux systems

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.