Soft links and hard links in Linux

Reference article

1. Soft link

  1. Concept: Soft links are also called symbolic links. Soft link files have shortcuts similar to Windows . It is actually a special file. In a symbolic link, the soft link file is actually a text file that contains the location information of another file .
  2. Usage: ln -s source file target file
    Example:

ln -s libwiringPi.so.2.70 libwiringPi.so

This will generate a soft link named libwiringPi.so pointing to libwiringPi.so.2.70

  1. Function: 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 every required directory. We only need to put the file in a fixed directory, and then Just use the ln command to link to it in other directories without repeatedly occupying disk space.

2. Hard links

  1. Concept: Hard links refer to links through index nodes. In the Linux file system, files stored in disk partitions are assigned a number regardless of their type, called an Inode Index. In Linux, multiple file names pointing to the same index node exist. Generally this kind of link is a hard link.
  2. Usage: ln source file target file
    Note: no parameter -s
  3. Function: Allows a file to have multiple valid path names, so that users can create hard links to important files to prevent "accidental deletion". The reason is as mentioned above, because there is more than one link to the index node of the directory. Deleting only one link does not affect the index node itself and other links. Only when the last link is deleted, the data blocks of the file and the links to the directory will be released. In other words, the condition for the file to be truly deleted is that all hard link files related to it are deleted .

3. Attention

  1. The ln command will maintain the synchronization of each linked file . That is to say, no matter where you change, other files will have the same changes, whether they are soft links or hard links.
  2. A soft link will only generate a mirror image of a file at the location you select and will not take up disk space . A hard link will generate a file with the same size as the source file at the location you selected , whether it is a soft link or Hard links and files keep changing synchronously.

Guess you like

Origin blog.csdn.net/m0_68038554/article/details/131975023