Link files in linux-soft links and hard links

Source: Internet
Author: User

First, the link file introduction

The "Linked files" in the Linux operating system are broken down into hard links and soft links (symbolic link). The essential difference between the two types of links is the inode. The following is a detailed description:

    • Hard link: When the system is going to read a file, the Inode information is read first, and then the data is taken out according to the information in the Inode to the block realm. The hard link is a direct re-establishment of the Inode link to the file placement of the Block field, that is hard to connect the contents of the file does not change, just add a point to the file Inode, and does not occupy additional disk space. There are two restrictions on hard links:
    1. Cannot cross file systems because different file systems have different inode table;
    2. The catalog cannot be linked.
    • Soft Links: Unlike hard links, a soft link is a separate file that, when read, forwards the read behavior to the file that the file is linked to. For example: Now there is a file a, we made a soft link file b,b point to A, when reading B, B will read the action forwarded to a, so that read the file a. When we delete file A, the link file B will not be affected, but if you read B again, you will be prompted not to open the file, but when we delete B, it will not have any effect on file a.

Second, how to establish soft links and hard links

Format of the LN command:LN [-S] [source file] [destination file]. The common option of this command is-s, if the non-S option is to establish a hard link, plus the-s option to establish a soft link (such memory, S->soft (soft)), for example:

Note: The du command in the example above is used to calculate the size of a file or directory, and-K is expressed in kilobytes, where 4 refers to the 4KB;LL command equivalent to Ls-l.

At the beginning of the directory there is only one passwd file, the total size of the directory is 4KB, after the hard link, although the size of two files is 2364B, but the total size of the directory does not change.

So let's try to delete the source files and then compare them, for example:

In the example above, the file size remains unchanged after the source file passwd has been deleted. Describes a hard-link file that does not replicate data blocks with extra disk space.

Look at another limitation of hard links--do not allow hard links to directories. Cases:

Soft Link Features

First set up a test directory 456, then copy the/etc/passwd file to do the test, and then give it a soft link file, for example:

In the example above, if you delete a source file, you cannot read the soft-link file , and you will see that the color changes when you use the command LL.

Description directory can not do hard links, but can do soft links, for example:

Linked files in Linux-soft links and hard links

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.