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

How to realize soft and hard Link ln in shell programming

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the relevant knowledge of "how to achieve soft and hard link ln in shell programming". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Define

Ln (short for link file) is the basic tool in the GNU core toolkit. This command establishes a synchronization link for a file in another location. When we need to use the same file in different directories, we do not need to put the same file in every directory we need. At this time, we only need to use ln to create a link to the corresponding file, without repeatedly occupying disk space.

Command format # hard link (source can only be a file) ln source target# soft link (source can be a file or directory) ln-s source target soft link

Soft link symbolic link is equivalent to shortcuts in Windows. Its content points to the location of another file. So you can create a soft link to a directory, or you can link to a file that doesn't exist. In addition, it can cross file systems. None of these three hard links can be achieved.

Hard link

Hard link hard link can be understood as an alias for a file, and there can be multiple aliases.

Principle

For Linux, the structure of the file is similar to that of Windows, consisting of the file name, inode (similar to the FCB file control block under Windows, saving some information about the file), and data. For example, if you create an origin file, you will get the following information.

Pay attention to Inode and hard links, and let's create a hard link hardlink for origin.

The comparison shows that the file hardlink that created the hard link is exactly the same as the original file origin except for its different names, just like the same person who has a formal name or a nickname. Their data are obviously exactly the same.

Next, we create a soft link softlink for origin.

By comparison, origin and softlink are completely different files, with different size, different blocks, different Inode, different type. The only connection is that the softlink file points to the origin file (which smacks of a file pointer).

Use case deletes the impact of source files on soft and hard links

As can be seen from the picture above, the number of hard links in hardlink is missing, while softlink still exists unscathed. Then we open the file through two links.

From the above picture, it is found that hardlink can still open the file, but the soft link cannot view the original file.

This is the end of the content of "how to realize soft and hard Link ln in shell programming". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Development

Wechat

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

12
Report