Rookie learning Linux-hard link and symbolic link

Source: Internet
Author: User
Tags disk usage

in LearningHard Linkwith theSymbolic Linkbefore, you need to know a little bit aboutInodewith theData Block. In theLinuxfile system, a file corresponds to aInodewith a number ofData Block. Inodewith theData Blockare identified by a number, such as30333aInode, the first20334aData Block. InodeAttributes of the file, such as the owner of the file, the owning user group, the permissions on the file, and a pointer to theData Blockthe pointer. The real content of the file is stored inData Blockin the. The contents of a file are divided into sections that are saved in differentData Blockin, throughInodeyou can find all the files corresponding to theData Block. UselsCommand and Open- I.option to view the file'sInodeNumber:

In Linux, there are two different kinds of link:

Hard Link: This link does not occupy disk space. For example, there is now a hard link named Jonathanfilehl pointing to JonathanFile.txt, in fact, Jonathanfilehl and JonathanFile.txt have the same inode. As in the following:

Symbolic Link: This link actually likes disk space. For example, there is now a symbolic link named Jonathanfilesl that points to jonathanfile.txt,jonathanfilesl and there will be separate inode and data block. The filename of the source file is saved in the symbolic link. Renaming or deleting the source file will cause symbolic link to fail. The following will prove it by example. Symbolic link is as follows:

The command to create the link is ln, and if the-s option is specified, Symbolic link will be created or hard link. To verify that you are taking up disk space, now look at the disk usage of the Jonathantestfolder folder:

Now create the hard link:ln JonathanFile.txt Jonathanfilehl

As the result shows, hard link does not take up disk space, and the inode is the same as the source file. Symbolic Link takes up disk space, create a symbolic link:ln-s JonathanFile.txt jonathanfilesl

Visible, Symbolic link does occupy disk space. Also, as mentioned above, if you modify the name of the source file or delete the source file, symbolic link will fail, but will not affect hard link:

The reason is also explained above: Symbolic link will be located through the source file name, and hard link through the inode to locate. More on the use of LN, or man a bit.

Related Article

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.