Two ways to connect files in Linux

There are two kinds of link files in Linux: symbolic link (soft link) and hard link.

1. The symbolic link is similar to the one under WindowsShortcut key methodFeature file.
2. The hard link generates a new file name through the inode connection of the file system instead of generating a new file .

Linux——inode:
Record file attributes, one inode per file. The inode is equivalent to the file ID. When searching for a file, the inode must be found first, and then the content of the file can be read.

ln command to create a connection file

ln [options] source file target file

Options: -s create a symbolic link (soft connection)
-f force the creation of a connection file, if the target exists, delete the target file first, and then establish the connection file.

ll -i //View inode

Hardwired

A hard link is that multiple files point to the same inode at the same time. Knowledge points:
1. Multiple files with the same inode are hard-linked files to each other, creating a hard-link is equivalent to having more entries for the file entity.
2. For hard-linked files, the file entity will only be deleted if the source file and all corresponding hard-linked files are deleted.
3. Regarding the characteristics of hard-linked files, we can prevent files from being deleted by mistake by creating hard-links to files.
4. Regardless of whether you modify the source file or link the file, the data of the other file will be changed.
5. The hard link cannot cross the file system
. 6. The hard link cannot connect to the directory.

Because of these limitations, hard links are actually not commonly used.

Symbolic connection (soft connection)

Symbolic links are similar to shortcuts under Windows, and symbolic links are also called soft links. Soft connections are often used. Symbolic link is equivalent to creating a separate file, this file will let the data read the file name of the file to which it is connected. The characteristics of soft connection:
1. Can connect to the catalog.
2. Can cross file system
3. After deleting the source file, the soft link file can not be opened
4. Symbol file indicates the specific link file through ==->==
5. Symbol link should use absolute path, otherwise There will be problems when copying. Using cp -d when copying will maintain the soft connection properties.
6. The symbolic link is equivalent to creating a new file, which will occupy the inode

Guess you like

Origin blog.csdn.net/qq_43690936/article/details/105936287