Do you know the difference between symbolic links and hard links and how to use them properly? I didn't know much about it, so I searched for related articles.
This article was intuitively easy to understand as a figure. Each feature is also written in an easy-to-understand manner. https://eng-entrance.com/linux-permission-link
Isn't it easy to understand the image of symbolic links as shortcuts?
Consider creating a symbolic link symkink_fname
that references a file called ʻoriginal_fname`.
./original_fname ./symlink_fname
here
cat ./symlink_fname
When you run
cat ./original_fname
Should mean the same operation as. In other words
rm ./symlink_fname
Is
rm ./original_fname
Will be equivalent to, and the original file ʻoriginal_fname` will be deleted.
Regarding this, the precautions when deleting symbolic links are described in this article, for example.
https://mimirswell.ggnet.co.jp/blog-165
The point is that you can delete the link with the rm
command, but it's dangerous, so let's use ʻunlink`.
On the other hand, what about hard links?
./original_fname ./hardlink_fname
Each path will point to the same entity file. In this state
open ./hardkink_fname
When you execute
open <Entity file>
It means. What's interesting is that there's something like a reference counter to a real file,
rm ./hardkink_fname
Will delete the path ./hardkink_fname
, but not the actual file.
Because, originally, the situation I'm thinking about now ./original_fname ./hardlink_fname Because there were two "references" in, even if one "reference" is deleted, one still remains.
And when the number of "references" becomes 0, the entity seems to be deleted.
Until now, we have used the words "entity" and "reference" to grasp the image, but to explain it properly, we need to touch the inode.
Is this article easy to understand? https://qiita.com/katsuo5/items/fc57eaa9330d318ee342
It seems that symbolic links are commonly used. So when are hard links used?
Read the answer to this question, I see! I think. https://q.hatena.ne.jp/1265361495
It is said that the destination is used to refer to the mail of multiple people on the IMAP server. It means that you don't have to copy it and it will be deleted properly.
...I learned a lot!
Recommended Posts