Discuss soft link and hard link again, incidentally, the difference between hard link and deep copy in vernacular

Discuss soft link and hard link again

  1. Use format
  • Soft link: ln -s designated path/source file name execution path/soft link name
  • Hard link: ln designated path/source file name designated path/hard link name
  1. Precautions
  • Creating a soft link is equivalent to creating an open shortcut for a file or directory. It is strongly recommended to use absolute paths when locating source files. The root cause of the problem is that when a relative path is used to create a soft link, the soft link will fail after the soft link is moved;
    Insert picture description here

  • In the process of creating hard links, I have heard some students discuss that it is similar to deep copy. What I want to say is that this is a big mistake.

  • Let’s talk about deep copy first. Deep copy is equivalent to copying all the contents of the source file. It also opens up a new storage address, so when one of the objects is modified, the other object will not be affected; then let’s take a look at the hard copy. Links, let’s talk about what hard links are for. The function of hard links is to create hard links to important files and prevent file data from being deleted by mistake.

  • The reason why the process of creating a hard link is different from the process of deep copying is because: creating a hard link does not open up a new memory space, but refers to the memory space address of the source file. When any one of them is modified , The other will also be affected.
    Insert picture description here

  • Of course, when we delete the source file, we can still access the data using hard links. Similar to the logic of the Hydra, only after all the heads of the Hydra are cut off, the Hydra will die. In other words, when I delete the source files and hard links, the data will be completely lost.

  • Remarks: This blog is only for teaching convenience, not as a professional technical guide. If it is helpful to you, please bookmark, like, comment, and follow.
    Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41475067/article/details/112172758