Linux soft and hard link differences

Source: Internet
Author: User


(1) Hard links

In general, the file name and inode number are the "one by one correspondence" relationship, and each inode number corresponds to a file name. However, the Unix/linux system allows multiple filenames to point to the same inode number. This means that the same content can be accessed with different file names, and changes to the contents of the file affect all file names, but deleting a file name does not affect access to another file name. This is referred to as a "hard link".

hard links must be in a partition, two files each other source, hard, delete one and one. Multiple files share an inode. is to save Inode resources. The contents of the multiple files are synchronized .

A hard link can be considered not a file, it is just an alias of the actual file, it is to prevent the real file is mistakenly manipulated, after a hard link to a file, they alias each other, delete any of them, only delete the alias, the actual file will not be deleted. Because only aliases do not have any additional information, they do not occupy the original file size of disk space.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/86/A3/wKiom1fGX3DgDaNgAAA-eOlP8aE191.jpg-wh_500x0-wm_3 -wmp_4-s_359339414.jpg "title=" 08d406aae1a48e01d28f12535a4bc1e4_thumb.jpg "alt=" Wkiom1fgx3dgdangaaa-eolp8ae191.jpg-wh_50 "/>

Examples of hard links are:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/86/A3/wKioL1fGYTXRlGSFAAB17fEKxWY876.png "title=" Screenshot from 2016-08-31 12:44:24.png "alt=" Wkiol1fgytxrlgsfaab17fekxwy876.png "/>


(2) Soft link

Can not be a partition, only one of the most essential source files. Delete the source and the other will fail. The inode number of the two files is different. The source file has a 100M link file that may only be dozens of K. Linked files are just a springboard for accessing source files.

A soft link file is a bit like a shortcut to Windows. It is actually a kind of special file. In a symbolic connection, a file is actually a text file that contains location information for another file.

Soft link is another file, function can be understood as a pointer, action on this file operation in addition to the deletion are directly to the actual point to the file, because it is a real file, so occupy disk space.


650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/86/A3/wKioL1fGX4rA9LrOAABnYBQeA6E510.jpg-wh_500x0-wm_3 -wmp_4-s_1122116407.jpg "title=" 80c3c3453d9bdf1f45a02bd4cd51fa2c.jpg "alt=" Wkiol1fgx4ra9lroaabnybqea6e510.jpg-wh _50 "/>

Examples of soft links are:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/A4/wKiom1fGYZXD2JpsAAB7rfrgqSY636.png "title=" Screenshot from 2016-08-31 12:45:32.png "alt=" Wkiom1fgyzxd2jpsaab7rfrgqsy636.png "/>


Summarize:

The main differences between hard links and soft links are:

(1) Soft links can cross the file system, hard links are not available.

(2) Hard links no matter how many, are pointing to the same inode, will increase the number of inode links as long as the inode link number is not 0, the file exists, regardless of whether you delete the source file or the linked file. As long as there is a existence, the file exists (in fact, there is no source file link file, because they point to the same iNode) when you modify the source file or link to any one of the files, the other files will be synchronized changes. Soft links do not use inode numbers directly as file pointers, but instead use file path masterpieces as pointers (soft links are not the same as the inode of the source file). So deleting a linked file has no effect on the source file, but deleting the source file will not find the file you want to point to. The soft link has its own inode, and there is a small space on the disk to store the path name.

(3) A soft link can be linked to a nonexistent file name.

(4) Soft links can be linked to the directory, and hard links are not available.

(5) Soft links save space resources, hard links save Inode resources.

 

This section mentions the Inode concept several times and I'll explain it in more detail in the next blog post.

This article from the "Technology life, Simple not simple" blog, please be sure to keep this source http://willis.blog.51cto.com/11907152/1844708

Linux soft and hard link differences

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.