The difference between hard links and soft links in Linux
1. In principle:
Hard link:A is a hard link to B (both A and b are filenames), the Inode node number in A's directory entry is the same as the Inode node number in the directory entry for B, that is, an inode node corresponds to two different file names, two file names point to the same file, A and B are completely equal to the file system. If one is deleted, it has no effect on the other one. each additional file name increases the number of links on the Inode node by one, each deleting a corresponding file name, and the number of links on the Inode node is reduced by one until the 0,inode node and the corresponding data block are recycled. Note: Files and filenames are different things, rm a deletes only a this file name, and a corresponding data block (file) only when the Inode node link number is reduced to 0 will be collected by the system.
Soft links (soft link):A is a soft link to B (both A and b are filenames), the Inode node number in A's directory entry is not the same as the Inode node number in directory item B, a and B point to two different inode, and then point to two different blocks of data. However, A's data block is only the path name of B (which can be used to find the directory entry for B). A and B are "master-slave" relationships, and if B is deleted, a still exists (because two are different files), but pointing to an invalid link.
2. Restrictions on use:
Hard Links:
A. you cannot create a hard link to a directory for several reasons, most importantly: The file system cannot have a link ring (".." When the directory was created). Except, this system can be identified), the consequences of the existence of the ring will cause such as file traversal and other operations such as chaos (du,pwd, such as the operation of the principle is based on file hard link, by the way, the second column of the ls-l result is also the number of hard links of the file, that is, the Inode node number of links)
B: You cannot create a hard link to a different file system, that is, two file names are under the same file system.
C: You cannot create a hard link to a nonexistent file, and the reason can be understood by the principle.
Soft Links:
A. You can create a soft link to a directory, and the traversal operation ignores the soft link of the directory.
B: can cross file system
C: You can create a soft link to a nonexistent file, because it's just a string, and the string is a different thing for a real file.
3. Command
Hard Links: ln source file Link Name
Soft Link: ln-s source file Link name
What is the difference between a hard link and a soft connection in Linux?