Soft connection and hard connection

Source: Internet
Author: User

First, you need to make it clear that in {
Tagshow (Event)
} "> Linux {
Tagshow (Event)
} "> In the system, the kernel creates {
Tagshow (Event)
} "> An inode (index node) is assigned to a file. Each file has a unique inode number. The file attributes are stored in the index node. when accessing the file, the index node is copied {
Tagshow (Event)
} "> Exists, allowing quick access to files.

A link is a way to establish a connection between a shared file and several directory items of the users who access it. Linux contains two types of links: hard link and soft link. Soft link is also called symbolic link ).

 

 

The following are some examples:

$ LS-il
13058-rwx---1 longcheng 48 Aug 16:38 file1
13059-rwx---1 longcheng 57 Aug 17 16:40 file2
$ Ln file2 file2hard
$ LS-il
13058-rwx---1 longcheng 48 Aug 16:38 file1
13059-rwx--2 longcheng 57 Aug 17 16:40 file2
13059-rwx--2 longcheng 57 Aug 17 16:40 file2hard

To create a soft link, add the option-s After LN. The following is an example:

$ LS-il
13058-rwx---1 longcheng 48 Aug 16:38 file1
13059-rwx--2 longcheng 57 Aug 17 16:40 file2
13059-rwx--2 longcheng 57 Aug 17 16:40 file2hard
$ Ln-s file1 file1soft
$ LS-il
13058-rwx---1 longcheng 48 Aug 16:38 file1
13059-rwx--2 longcheng 57 Aug 17 16:40 file2
13059-rwx--2 longcheng 57 Aug 17 16:40 file2hard
13061 lrwxrwxrwx 1 longcheng 5 Aug 17 16:58 file1soft-> file1

 

 

Soft links also have the disadvantage that hard links do not exist. Because the link file contains the path information of the original file, when the original file is moved from one directory to another, access the link file, the system won't be able to find it, and the hard link won't have this defect. You can move it as you want; it also requires the system to allocate additional space for creating new index nodes and saving the original file path.

 

Here is another example:

Suppose there is a file SRC and HL is a hardlink of it, a new file index will be created, and SRC will use the same I-node. After SRC is deleted, you can still access the file content through Hl. In fact, after HL has been established, HL and SRC are exactly the same. You can even say that SRC is a hardlink of HL.

Create a SRC symbol link with the name SL. Then Sl is just a special file, which records the SRC file name and path (the specific content depends on the parameters for executing the ln command ). Sl has its own I-node. When SRC is deleted, SL becomes invalid.

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.