Linux file system soft link hard link

Source: Internet
Author: User

To understand the soft and hard links, we need to start with the storage principle of the Ext file system.

The smallest storage unit on the hard disk is sector, which is 512bytes in size.

Because data tends to be larger than 512bytes, we connect multiple sector to store data, and this is done to reduce the burden of disk I/O

This multiple connected sector is called block. Block size is 2 n times 512bytes

Storage space is divided into: Data area and metadata area

Data area: Block stores real data, typically 1kb 2kb, 4KB

Metadata area: Inode storage metadata, including Inode index, name, size, modification time, etc., Inode 128bytes

Ls–i can view the index number of the file corresponding to

Stat can view inode information for a file

The index label in the inode information should correspond to the index number that erases the file information, for example, the index number of a file is 1052822

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/88/wKioL1WfbFLyotK9AABQuV7bUxw826.jpg "style=" float: none; "title=" 1.png "alt=" Wkiol1wfbflyotk9aabquv7buxw826.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/8C/wKiom1WfaoLhMRJXAAC3HOvfgps136.jpg "style=" float: none; "title=" 2.png "alt=" Wkiom1wfaolhmrjxaac3hovfgps136.jpg "/>

It is necessary to note that directories and files do not have the same nature as the contents of block storage

The file stores the contents of the file itself

Directory to store the Inode index and file name of all files in the directory, which is intended to help locate files or other directories


The diagram details the process of accessing the file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6F/8C/wKiom1WfasaDbQSBAAFCAzolYgU223.jpg "title=" 3.PNG " alt= "Wkiom1wfasadbqsbaafcazolygu223.jpg"/>


after understanding, let's say Hard Links


Let's consider if there is a B file under the/tmp directory, its inode index and a also point to the same inode

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/8C/wKiom1WfZ8qQwqACAAB3QAbx7MA689.jpg "title=" 4.PNG " alt= "Wkiom1wfz8qqwqacaab3qabx7ma689.jpg"/>

This is the hard link that we are A/b is each other

The view is ls–l A or ls–l B, there is a 2 in front of the master, which means there is another hard link

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6F/88/wKioL1WfacLx5TG_AABohThHcNY392.jpg "title=" 5.PNG " alt= "Wkiol1wfaclx5tg_aabohthhcny392.jpg"/>

Command: LN is linked file link file such as ln a B


Soft links

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/88/wKioL1Wfaf3SDOxDAAChn7C1tog465.jpg "style=" float: none; "title=" 6.PNG "alt=" Wkiol1wfaf3sdoxdaachn7c1tog465.jpg "/>


The inode of B points to the path of a file, and then finds the inode by this path

See how it works

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6F/8C/wKiom1WfaCuCQgAnAABw4ES0WIA753.jpg "style=" float: none; "title=" 7.PNG "alt=" Wkiom1wfacucqganaabw4es0wia753.jpg "/>



The b here is pointing to a, and the size is 1 bytes. That's a relative path.

Command: Ln–s linked file link file such as ln–s a B

The difference between soft and hard links

Soft Links:

· Can be linked across partitions-because only the path is pointed

· can link files or directories

· Delete does not affect source files-similar to Windows shortcut keys

Hard Links

· Cannot cross-partition links-The inode should only be pointed to by files in this area

· Cannot link directory-directories under directory may point to parent directory, resulting in a dead loop

· Delete the number of Inode links reduced to 0 in the entire file delete



This article is from the "Robbie" blog, make sure to keep this source http://jzrobbie.blog.51cto.com/6535329/1672880

Linux file system soft link hard link

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.