In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the difference between soft links and hard links under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the difference between soft links and hard links under Linux.
Links under Linux
As a Linux user, the Linux system provides ln instructions to link files. We must have seen instructions similar to the following:
At this point, if ls looks at the files in the current directory, he will find:
So what on earth is this foo.txt?
This is a file link, file links are mainly divided into hard links and soft links, by looking at ln-help, you can see some important content:
The ln directive creates hard links by default, and if the-s parameter is added, a soft link is generated.
Hard link
First, let's take a look at the hard links created by ln by default. Because files under Linux are identified by index nodes (Inode), files saved in disk partitions in the Linux file system are assigned a number, called index node number (Inode Number), no matter what type they are.
In Linux, there are multiple filenames pointing to the same Inode, so a hard link is a connection made through an Inode, that is, each hard link is a file pointing to the corresponding area.
Let's create a file foo.txt here and set up a hard link to it:
The first 6817859 is the inode of the file, which can simply be thought of as a pointer in the C language. It points to a block of the physical hard disk. In fact, the file system maintains a reference count. As long as there is a file pointing to this block, it will not disappear from the hard disk. Here, we will find that the two files have the same inode. By looking at the contents of the file, we will find that it is the same file:
The function of hard links is to allow a file to have multiple valid pathnames, so that users can establish hard links to important files to prevent "accidental deletion". Since there is more than one connection to the index node of the directory, suppose we delete the original foo.txt file:
At this time, the contents of the file still exist, so deleting only one connection does not affect the Inode itself and other connections. Only when the last link is deleted will the connection of the file block and directory be released, that is, the file will be actually deleted.
Soft link
Soft links, also known as symbolic links, this file contains the path name of another file, for example, in the image above, foo.txt is the soft link of bar.txt, bar.txt is the actual file, and foo.txt contains a record of the inode of bar.txt.
Soft connection can be any file or directory, and you can link files of different file systems. when reading or writing symbol files, the system automatically converts this operation into the operation of the source file, but when deleting the linked file, the system only deletes the linked file, not the source file itself, which is similar to the shortcut under the Windows operating system.
The difference between soft links and hard links
With the above knowledge, we can briefly answer the questions in the interview:
What is the difference between soft links and hard links?
Let's sum it up:
At this point, I believe you have a deeper understanding of "the difference between soft links and hard links under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.