Differences between hard links and symbolic links

Source: Internet
Author: User

Collation

.

The file attributes are stored in the index node. when accessing the file, the index node is copied to the inner to implement fast file access.

 

 

 

Two links in Linux

Linux contains two types of links: Hard Link and Soft Link. Soft link is also called Symbolic Link ).

Hard Link

Hard links can also be considered as a pointer to a file index node. The system does not re-allocate inode for it,

Each time a hard link is added, the number of file links is increased by 1, and the number of deleted links is reduced by 1.

. Only Super Users can do this on a system that allows the creation of directory hard links.

(These restrictions are not mandatory in POSIX ).

 

Syntax for creating hard links: new files with ln

SingleFile; create an empty file root 0 Mar 30 SingleFile HardLinkFile root 0 Mar 30 HardLinkFile-rw-r -- root 0 Mar 30 SingleFile # "Hello" root 6 Mar 30 HardLinkFile-rw-r -- root 6 Mar 30 SingleFile HardLinkFile; display the contents of the new file HardLinkFile; Delete the new file (delete the old file is the same) root 6 Mar 30 SingleFile

 

 

Soft link (symbolic link)

Contains references to another file/directory in the form of absolute/relative paths.

Soft links can be seen as indirect pointers to a file, which is equivalent to shortcuts in windows.

When creating a soft link to a file, the soft link uses a new inode. Therefore, the inode Number of the soft link is different from the inode Number of the file (indicating that they are two different files ),

When we create this file again (the file name is the same as the previous one), the soft link points to this file again (the inode number is different from the previous one ), hard links are not affected.

Of course, 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 cannot find it,

However, hard links do not have this defect. You need to move them as much as you want. In addition, the system needs to allocate additional space for creating new index nodes and saving the original file path.

 

Soft link creation Syntax: New file in ln-s

SingleFile; create an empty file SingleFile SoftLinkFile; create a soft link root 0 Mar 30 SingleFile rwxrwxrwx root 10 Mar 30 SoftLinkFile SingleFile; Delete the source file (or move it to another location) rwxrwxrwx root 10 Mar 30 SoftLinkFile # "World" total 4 root 6 Mar 30 SingleFile rwxrwxrwx 1 root 10 Mar 30 SoftLinkFile SingleFile #

 

Differences between hard link and soft link

 

Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------------

References:

Http://blog.chinaunix.net/uid-23208702-id-75180.html

Http://blog.csdn.net/zengmuansha/article/details/7814496

Http://en.wikipedia.org/wiki/Soft_link

Http://blog.sina.com.cn/u/2827812045

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.