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 are the differences between symbolic links and hard links in linux

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

What are the differences between symbolic links and hard links in linux? most people do not understand the knowledge points of this article, so the editor summarizes the following contents to you, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article, "what is the difference between symbolic links and hard links in linux?"

Differences: 1, hard links when the file rename or file movement will not change the link to, symbolic links when the file renaming or file movement will make the link broken; 2, hard links can only link files, symbolic links can link files and folders; 3, symbolic links can be created across different file systems, hard links can not be created across different file systems.

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the difference between symbolic links and hard links in linux

There are two different types of links in linux, soft links and hard links. Modify one of them. The hard link points to the node (inode) and the soft link points to the path (path).

A soft connection file, also called a symbolic link, contains the path name of another file, similar to a shortcut under win

Difference:

File renaming or file movement

File renaming and file movement are both changes to the absolute path of the file to the Linux system. For hard links, file renaming or file movement will not change the link point, while for soft links, file renaming or file movement will break the link, and when the file content is modified through the soft link, a new inode will be created again, associated with the original file name and file data block.

File deletion

The rm command or nodejs's unlink actually subtracts the number of links from inode by 1. For the hard links mentioned above, deleting test_hard.txt makes the number of links in inode1 become 1. When the number of links becomes 0, the system will release the inode, and new files created later can use the inode number of the inode. There is no inode pointing to the file data block, so the file cannot be found. But in fact, the file data is still on the hard disk, so you can often see some tools on the Internet to help recover mistakenly deleted files. The number of soft link inode links is 1. Delete the soft link and the system releases the inode.

Link files and folders

Soft links can link files and folders, but hard links can only link files.

Create links for different file systems

Soft links can be created across different file systems, but hard links are not, because hard links share an inode, while different file systems have different inode table.

Application scenario

Hard link

File backup: in order to prevent important files from being deleted by mistake, file backup is a good way, but copying files can lead to disk space consumption. Hard links can back up files without taking up disk space.

File sharing: when multiple people work together to maintain the same file, you can create a hard link in a private directory by means of hard links, so that everyone's changes can be synchronized to the source file, but avoid the problem of someone mistakenly deleting the file.

File classification: different file resources need to be classified, for example, if the classification of a movie is foreign or suspense, then we can create hard links in foreign folders and suspense folders respectively. in this way, you can avoid wasting disk space by repeatedly copying movies. Some people may say, isn't it okay to use soft links? Yes, but not so good. Because once the source file is moved or renamed, the soft link is invalid.

Soft link

Shortcuts: for files with deep paths, it is not easy to find them. Using soft links to create shortcuts on the desktop, you can quickly open and edit files.

Flexible switching program version: for programs that have multiple versions on the machine at the same time, you can quickly change the program version by changing the direction of the soft link. It is mentioned here that switching between python versions can be done.

The above is about the content of this article on "what is the difference between symbolic links and hard links in linux?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

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