A Brief Introduction to hard and soft connections in Linux

Source: Internet
Author: User

Reference connection: http://hi.baidu.com/deep_pro/item/245bd7e80f154ad5ea34c915

Http://hi.baidu.com/adokaixin/item/9d34b381235a1428110ef34d

Http://www.cnblogs.com/itech/archive/2009/04/10/1433052.html

Here we mainly introduce hard connection and soft connection, and their functions. The third link provides clear explanations. We recommend that you take a closer look.

 

In Linux, there are two types of connections: hard link (hard link) and soft link (symbol link). The corresponding command is ln. By default, if ln is not added with parameters, a hard connection is generated. Ln
-S generates soft connections.

Hard connection: the directory cannot create a hard connection.

Test;

Qxd @ Ubuntu :~ $ Mkdir hello

Qxd @ Ubuntu :~ $ Ln Hello/test

LN: 'Hello/': hard link not allowed for directory

 

Hard join is performed by indexing nodes. In Linux, the stored file will have a number called the inode index ). In Linux, multiple file names direct to the same index node.

A hard connection allows a file to have multiple valid path names. In this way, you can create a hard connection to an important file to prevent "accidental deletion. The function of soft connection is equivalent to the shortcut in windows, but a simple pointer connection.

 

The following experiment is used to verify:

The soft connection only occupies two bytes, while the hard connection F2 actually occupies the same size as the source file F1. In this case, deleting F1 does not affect F2, but the soft connection f_s is invalid. The source file is completely deleted only after all the hard connections are deleted.

 

Ln usage: ln [-options] Source Target

In addition, a connection can be created only between files in the same file system.

 

A soft connection can be understood as a pointer. Operations on this file, except deletion, are directly redirected to the actual file. Because it is a real file, it occupies disk space. In the second connection, hard connection does not occupy the disk space of the original file. I don't understand what it means here. The actual experiment result is:

If you perform a read/write operation on the f_s symbol, it will be directly reflected in the original file F1, and F2 will be changed as a hard connection. The hard connection operation on F1 or F2 will change.

Therefore, I think hard connection is mainly used for backup to prevent accidental deletion. soft connection is a shortcut that facilitates our daily use without occupying too much storage space.

 

Alas, a lot of things will be forgotten without review. I am a cainiao and want to continue learning.

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.