Linux hard link and soft link difference ____linux

Source: Internet
Author: User

1.Linux Link Concept
There are two kinds of Linux links, one is called hard link (Hard link), the other is called Symbolic link (symbolic link). By default, the LN command produces a hard link.

"Hard Connection"
A hard connection refers to a connection through an index node. In a Linux file system, a file stored in a disk partition is assigned a number, called an index node number (Inode index), regardless of its type. In Linux, multiple file names point to the same index node. Generally this connection is a hard connection. The effect of a hard connection is to allow a file to have multiple valid pathname, so that users can build hard connections to important files to prevent "accidentally delete" functionality. The reason for this is as described above because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the index node itself and other connections, and only when the last connection is deleted will the file's data block and directory connections be freed. That is, the condition that the file is actually deleted is that all of the hard connection files associated with it are deleted.

"Soft Connection"
Another connection, called a symbolic connection (symbolic link), is also called a soft connection. Soft link files have shortcuts similar to Windows. It's actually a special file. In a symbolic connection, a file is actually a text file that contains the location information for another file.

2. Deepen understanding through experiments
[oracle@linux]$ Touch F1 #创建一个测试文件f1
[oracle@linux]$ LN F1 F2 #创建f1的一个硬连接文件f2
[oracle@linux]$ Ln-s F1 F3 #创建f1的一个符号连接文件f3
[oracle@linux]$ Ls-li #-I parameter displays the Inode node information of the file
Total 0
9797648-rw-r--r--2 Oracle Oinstall 0 APR 08:11 F1
9797648-rw-r--r--2 Oracle Oinstall 0 APR 08:11 F2
9797649 lrwxrwxrwx 1 Oracle oinstall 2 APR 08:11 f3-> F1

From the results above, it can be seen that the hard connection file F2 and the original file F1 the Inode node is the same, are 9797648, however, the inode node of the symbol connection file is different.

[oracle@linux]$ Echo ' I am F1 file ' >>f1
[oracle@linux]$ Cat F1
I am F1 file
[oracle@linux]$ Cat F2
I am F1 file
[Oracle@linux]$ Cat F3
I am F1 file
[oracle@linux]$ rm-f F1
[oracle@linux]$ Cat F2
I am F1 file
[Oracle@linux]$ Cat F3
Cat:f3:No such file or directory

Through the above test can be seen: when the original file F1 deleted, hard connection F2 is not affected, but the symbolic connection F1 file is invalid

3. Summary
In this way you can do some related tests, you can get all the following conclusions:
1). Delete Symbol connection F3, have no influence to f1,f2;
2. Delete Hard connection F2, also have no influence to f1,f3;
3. Delete the original file F1, the hard connection F2 has no effect, resulting in symbolic connection F3 failure;
4. At the same time delete the original file F1, hard connection F2, the entire file will be really deleted.

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.