1.Linux Link Concept
There are two types of Linux links. One is called a hard link, and there is also a symbolic link called symbolic links. 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 stored 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.
Generally, such a connection is a hard connection.
The purpose of a hard connection is to agree that a file has multiple valid pathname names. This allows the user to establish a hard connection to the critical file. To prevent "accidental deletion" of the function. The reasons are as above. Because the corresponding index node for the folder has more than one connection.
Simply deleting a connection does not affect the index node itself and other connections. Only after the last connection has been deleted. The connection of the file's data block and folder will be released. That is, the condition that the file is actually deleted is that all the hard connection files associated with it are deleted.
"Soft Connect"
The second type of connection is called a symbolic connection (symbolic link), also called a soft connection. A soft-link file has a shortcut similar to Windows. It's actually a special file. In a symbolic connection, the file is actually a text file. It includes location information for a 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
From the above results can be seen. The hard-connect file F2 the Inode node of the original file F1 is 9797648, but 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
Through the above test can be seen: when the original file F1, hard connection F2 is not affected, but the symbolic connection F1 file is invalid
3. Summary
In this way you can do a number of related tests to 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. There is no effect on the hard connection F2, which causes the symbolic connection F3 to fail;
4). Delete the original file F1 at the same time, hard connect F2. The entire file will actually be deleted.
End.
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Linux soft and hard wiring connection