Linux create link

1 Introduction:


[Soft link]:
Symbolic link (Symbolic Link), also called soft link, a soft link file has a shortcut similar to Windows, it is actually a special file, in a symbolic link, the file is actually a text file, It contains the location information of another file.


[Hard link]:
Hard link refers to linking through an index node. In the Linux file system, files stored in disk partitions are assigned a number, which is called an inode index, regardless of their type.
In Linux, multiple file names point to the same index node. Generally, this kind of link is a hard link. The function of a hard link is to allow a file to have multiple valid path names, so that users can establish hard links to important files. In order to prevent the "incorrect deletion" function, because the index node corresponding to the directory has more than one link, deleting only one link does not affect the index node itself and other links, only when the last link is deleted, the data block of the file And the link to the directory will be released, that is, the condition for the file to be deleted is that all hard-linked files related to it are deleted.


2. Create a soft link:

When we need to use the same file in different directories, we don’t need to put a file that must be the same in each directory that we need. We just need to put the file in a fixed directory, and then put it in other directories. You can use the lncommand link to link it under the directory of the directory , so there is no need to repeatedly occupy the disk space

ln  -s  源文件  目标文件

get:目标文件 -> 源文件

3. Create a hard link:

ln  源文件  目标文件

Note 1: The lncommand will keep the synchronization of each linked file, that is to say, no matter which one you change, the other files will have the same changes;
Note 2:It ln -swill only generate a mirror image of a file at the location you selected. It will not take up disk space, hard links ln, and no parameters -s. It will generate a file with the same size as the source file at the location you selected, whether it is a software Whether the link is
a hard link, the files keep changing in sync.

Guess you like

Origin blog.csdn.net/lcx1837/article/details/113480778