[Soft and hard links of Linux system]

There are two types of links in Linux: hard links and soft links. Soft links are also called symbolic links.

 

Create command:

ln -s destfile/directory softlink #Establish   a soft link 

ln destfile hardlink #Establish                   a hard link

 

inode

In the Linux system, the kernel assigns an inode to each newly created file, and each file has a unique inode number. We can simply understand the inode as a pointer, which always points to the specific storage location of this file. The file attributes are stored in the inode, and when the file is accessed, the inode is copied to the memory, thereby realizing fast access to the file. The system locates each file by inode.

 

hard link

A hard link is actually a pointer to the inode of the source file, and the system does not reallocate the inode for it. Hard links will not create new inodes. No matter how many hard links there are, they all point to the same inode node. Just creating a new hard link will increase the number of node connections. As long as the number of node connections is not 0, the file will be It's always there, no matter if you delete the source file or the linked file. As long as there is one, the file exists (in fact, the concept of reference counting). When you modify either the source file or the linked file, the other files will be modified synchronously. Since the file system in the Linux system queries data by accessing inodes, a hard link means that two different file names point to the same inode, and the two will not affect each other. Delete one and the other exists. The number of links will increase.

 

soft link

The most intuitive explanation of soft links: equivalent to the shortcut of Windows system, it is an independent file (with independent inode, independent of the inode of the source file), the content of the file is the path pointer of the source file, and the source file can be accessed through this link. document. So deleting the soft link file has no effect on the source file, but deleting the source file, the soft link file will not find the file to point to (it can be analogous to the shortcut on Windows, you can click on the shortcut to access a certain file, but delete the shortcut , has no effect on the source file). The symbolic link is different. For example, file A points to inode number 123456, and the content in file B is only the path of file A, so no matter whether A or B is opened, A is accessed at the end, which is a bit like a shortcut under Windows. Deleted, B can not be used normally. The number of links remains unchanged.

 

 

the difference

1. Soft link and source file operation permissions are different; hard link and source file operation permissions are exactly the same.

2. Soft links can cross file systems (partitions); hard links do not allow cross file systems due to inode limitations and the unmountability of file systems.

3. Soft links can connect to a non-existing file name; hard links cannot.

4. Soft links can connect directories; hard links cannot.

5. Hard links cannot span file systems and cannot connect directories. Because if the directory is hard linked, then all files in this directory must establish hard links, and when new files are created in the future, new hard links must be created, which is too complicated for the computer.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326708118&siteId=291194637