Hard links and links (symbolic links)

Source: Internet
Author: User

Linked commands: Ln-make links between files #在文件之间创建一个链接

Creating a hard link adds additional record entries to reference the file

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/85/4B/wKiom1efN9SSXmgVAAAuNQce8E0172.jpg "title=" 1.jpg " alt= "Wkiom1efn9ssxmgvaaaunqce8e0172.jpg"/>

Figure 1 is the number of links = number of names of files


Will/mnt/f1 do a hard link to/opt/f1 name or F1

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/85/4B/wKioL1efOCTzgJL1AAAu5-e-bGU469.jpg "title=" 2.jpg " alt= "Wkiol1efoctzgjl1aaau5-e-bgu469.jpg"/>

In the diagram, the metadata of both files indicates that the same file


650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/85/4B/wKiom1efOEPi8nzfAABNmScbOYE307.jpg "title=" 3.jpg " alt= "Wkiom1efoepi8nzfaabnmscboye307.jpg"/>

The number of links is 2.



Then rename the source file and add the content

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/85/4B/wKiom1efOg3h_451AAB69OizV3A428.jpg "style=" float: none; "title=" 4.jpg "alt=" Wkiom1efog3h_451aab69oizv3a428.jpg "/>

As you can see, their metadata is still the same, stating the same file, and then we

see if their content is the same 650) this.width=650; "Src=" http://s4.51cto.com/wyfs02/M00/85/4B/ Wkiol1efof-q5pvbaabc-shwlrk858.jpg "title=" 5.jpg "style=" Float:none; "alt=" wkiol1efof-q5pvbaabc-shwlrk858.jpg "/ >

The results are obvious



So, when we delete the source file, will the linked file also be invalid or deleted? 650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/4B/wKioL1efOgaAWoRKAABf2aWRwfU231.jpg "title=" 6.jpg "style=" Float:none; "alt=" wkiol1efogaaworkaabf2awrwfu231.jpg "/>


The link file is still there, and the content is not lost. But the number of links minus 1

When the number of links is 0 o'clock. File is deleted

Corresponds to a physical file on the same file system

Each directory references the same inode number

Increase number of links at creation time


Hard links cannot span drives or partitions

Demonstrate

, the/testdir directory is a SDA5 partition with/opt not the same partition 650) this.width=650; src= http://s1.51cto.com/wyfs02/M02/85/4B/ Wkiol1efogqrfqdoaadxwndba2i515.jpg "title=" 7.jpg "style=" Float:none; "alt=" wkiol1efogqrfqdoaadxwndba2i515.jpg "/ >


Then we link the F1 to the/testdir directory 650) this.width=650; "Src=" http://s4.51cto.com/wyfs02/M02/85/4B/wKioL1efOg6xim_ Laabdarbmex4598.jpg "title=" 8.jpg "style=" Float:none; alt= "Wkiol1efog6xim_laabdarbmex4598.jpg"/>

Tip You cannot link across partitions. Why?

The essence of a hard link is the same file, add a new name to it, if not in a partition, even if the metadata is not the same file, so this violates the definition of hard link, so the system will not let you create


Hard links cannot create links to directories 650) this.width=650; "Src=" http://s2.51cto.com/wyfs02/M01/85/4B/ Wkiom1efogkieeejaaaynbvmmea182.jpg "title=" 9.jpg "style=" Float:none; "alt=" wkiom1efogkieeejaaaynbvmmea182.jpg "/ >



Symbolic (or soft) links

A symbolic link points to another file

ls-l the name of the display link and the referenced file

The content of a symbolic link is the name of the file it refers to

The directory can be

Can span partitions

does not increase or decrease the reference count of the target file inode;

Syntax: ln-s filename [linkname]


650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/85/4B/wKioL1efOgeBCS-WAABW7v8zar8374.jpg "title=" 10.jpg "Style=" Float:none; "alt=" wkiol1efogebcs-waabw7v8zar8374.jpg "/>

Soft Connect F1 named F11 View properties. Metadata is different, read and write permissions are different, the number of links does not increase, and the data size is different. 2 How did this data come about? is from the path, the path has several characters just a few

So a soft connection is not the same file as the original file.



When we delete the original file, the link file will be error-

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/85/4B/wKioL1efOgri-vJEAABCKiN0nRI517.jpg "title=" 11.jpg "Style=" Float:none; "alt=" wkiol1efogri-vjeaabckin0nri517.jpg "/>



650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/85/4B/wKiom1efOg-y9N-xAAAozZLn0xA958.jpg "title=" 12.jpg "Style=" Float:none; "alt=" wkiom1efog-y9n-xaaaozzln0xa958.jpg "/>

Link file is stored in the path data, when we access the link file, it will automatically go to the original file there, so when we deleted the original file, it used to find, hey! Without? So it's going to tell us: I can't find it!


Here's a very interesting thing: we use the VI editor in the original directory to create a new F1 to see if it can be distinguished.

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/85/4B/wKioL1efOgPgHYSuAAA4Q759v1s909.jpg "style=" float: none; "title=" 13.jpg "alt=" Wkiol1efogpghysuaaa4q759v1s909.jpg "/>

OK , this F1 is a former F1 brother!



650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M00/85/4B/wKioL1efOgeBCS-WAABW7v8zar8374.jpg "title=" 10.jpg "Style=" White-space:normal;float:none; "alt=" wkiol1efogebcs-waabw7v8zar8374.jpg "/>

The system did not recognize, it is only mechanical to give us a link, will not care about the past F1 or not F1. As long as the name is, it is the place that it knows.


The next step is to verify cross-partition, cross-device operations

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/85/4B/wKiom1efOgzwebmeAABqoeKGQ6c110.jpg "title=" 15.jpg "Style=" Float:none; "alt=" wkiom1efogzwebmeaabqoekgq6c110.jpg "/>

An error has been made. Why is it?

Because it can't be found. The path is not correct,

Command: Ln–s f1/testdir/f2

F1 the path should be relative to/testdir/f2

So the path should be written:/OPT/F1



The f22 here is right. No error 650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/4B/wKioL1efOhCwhErGAABm-wGiNSQ556.jpg "title=" 16.jpg "style=" Float:none; "alt=" wkiol1efohcwhergaabm-wginsq556.jpg "/>



There is also a situation where a soft link can be written in another way when it is in its subdirectory

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/85/4B/wKiom1efOgWxZwe1AABtQMs2VXI091.jpg "style=" float: none; "title=" 17.jpg "alt=" Wkiom1efogwxzwe1aabtqms2vxi091.jpg "/>

: Both PIG1 and Dog1 are in the TestDir directory


We will/testdir/dog/dog1/a file soft connection to/TESTDIR/PIG/PIG1/A1 from the name of A1 (really do not know what filename good, everyone don't laugh)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/85/4B/wKiom1efOgjDZKcDAABg3QtfZB0555.jpg "style=" float: none; "title=" 18.jpg "alt=" Wkiom1efogjdzkcdaabg3qtfzb0555.jpg "/>

Here, the soft connection A1 must write the absolute path, and the source file can write relative paths, where the relative path is relative to the soft connection A1.







This article is from the "11893416" blog, please be sure to keep this source http://11903416.blog.51cto.com/11893416/1833176

Hard links and links (symbolic 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.