Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between soft links and hard links

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

What is the difference between soft links and hard links? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Hard link (hard link): an is the hard link of B (An and B are both file names), then the inode node number in A's directory entry is the same as the inode node number in B's directory entry, that is, an inode node corresponds to two different file names, two file names point to the same file, and An and B are completely equal to the file system.

If one of them is deleted, it has no effect on the other. For each additional file name, the number of links on the inode node increases by one, and each time a corresponding file name is deleted, the number of links on the inode node decreases by one until the zero Inode node and the corresponding data block are recycled.

Note: the file and the file name are different things, rm An only deletes the file name A, and the corresponding data block (file) of A will only be recycled by the system when the number of inode node links is reduced to 0.

What is a soft connection?

Soft connection is a common command in linux, and its function is to establish a synchronous link for a file in another location.

(video tutorial recommendation: linux video tutorial)

The specific usage is: ln-s source file target file.

When we need to use the same file in a different directory, we don't need to put the same file in every directory we need, we just need to link (link) with the ln command in other directories, without repeatedly taking up disk space.

Difference:

1. Mount point

Hard links (Hard Link) can only be created between files on the same storage media, but not between files under different mount points. In the latter case, soft links can be used; (distinguish between different mount points and different directories of the same mount point)

2. Catalogue

A soft link is equivalent to a shortcut in win, that is, if a soft link to a directory is just a shortcut to a specified location, the operating system looks for this shortcut and directly finds the files in the real directory. But the hard link is equivalent to a mirror way, after creating a hard link to a directory, the operating system needs to make a hard link to all the files in this directory (copy a past). In this way, the operating system has to keep traversing when accessing this link, which greatly increases the complexity and is easy to enter the endless loop.

Hard links cannot create directories that are limited by the design of the file system. Directories in the Linux file system hide two special directories, the current directory and the parent directory. In fact, it is two hard links, if the system runs to create a hard link to the directory, it will produce a directory ring.

The answer to the question about what is the difference between soft link and hard link is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report