"Go" Linux soft connect and hard link

Source: Internet
Author: User

Review again, not much of the operation. Although the feeling will!!!

This time again to operate again!!

The above test found that after removing F1, the soft connection F3 was invalid, and the Hard link F3 was not affected.

Ls-f can see the type of file.

--------------------------------------------------------------------------------------------------------------- -

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

"Hard Connect"
A hard connection is a connection that is made through an index node. In a Linux file system, a file saved in a disk partition, regardless of the type, assigns a number to it, called the index node number (Inode index). In Linux, multiple file names point to the same index node that exists. In general, this connection is a hard connection. The purpose of a hard connection is to allow a file to have multiple valid pathname, so that users can establish a hard connection to important files to prevent "accidental deletion" of the function. The reason for this is as above, because there is more than one connection to the index node that should be the directory. Deleting only one connection does not affect the index node itself and other connections, and the connection to the file's data block and directory will be released only if the last connection is deleted. That is, the condition that the file is actually deleted is that all the hard connection files associated with it are deleted.

"Soft Connect"
Another connection is called a symbolic connection (symbolic link), also known as a soft connection. A soft-link file has a shortcut similar to Windows. It's actually a special file. In a symbolic connection, a file is actually a text file that contains location information for another file.

2. Deepen understanding through experimentation
[Email protected]]$ Touch F1 #创建一个测试文件f1
[Email protected]]$ LN F1 F2 #创建f1的一个硬连接文件f2
[Email protected]]$ ln-s F1 F3 #创建f1的一个符号连接文件f3
[[Email protected]]$ ls-li #-I parameter displays inode node information for a 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

As can be seen from the above results, the hard connection file F2 the same as the Inode node of the original file F1, all 9797648, however, the inode node of the symbolic connection file is different.

[Email protected]]$ echo "I am F1 file" >>f1
[Email protected]]$ Cat F1
I am F1 file
[Email protected]]$ cat F2
I am F1 file
[Email protected]]$ cat F3
I am F1 file
[Email protected]]$ rm-f F1
[Email protected]]$ cat F2
I am F1 file
[Email protected]]$ cat F3
Cat:f3:No such file or directory

As you can see from the above test, hard connection F2 is not affected when the original file F1 is deleted, but the symbolic connection F1 file is not valid

3. Summary
In this way you can do some related tests and get all the following conclusions:
1). Remove the symbolic connection F3, no effect on F1,F2;
2). Delete the hard connection F2, the F1,F3 also has no effect;
3). Delete the original file F1, the hard connection F2 has no effect, resulting in symbolic connection F3 invalid;
4). While deleting the original file f1, hard connect F2, the entire file will be really deleted.

Finish!

"Go" Linux soft connect and hard link

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.