In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the differences between hard links and soft links corresponding to files and directories in Linux?", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the difference between hard links and soft links corresponding to files and directories in Linux?"
Hard link
The newly created file is an alias for the existing file, and can still be used when the original file is deleted.
Hard link features:
1. Having the same I node and the same storage block can be regarded as the same file
2. It can be identified by I node, and the I node number is the same
3. Cannot be across partitions
4. Cannot be used for directories
5. Delete files and use hard links normally.
Soft link
Another kind of connection is called symbolic connection (Symbolic Link), also called soft connection. Soft-link files have shortcuts similar to Windows. It is actually a special file. In symbolic links, a file is actually a text file that contains information about the location of another file.
Soft link features:
1. Similar to windows shortcuts
2. The soft link has its own I node and block fast, but only the file name and I node number of the original file are saved in the data block, and there is no actual file data.
3. Lrwxrwxrwx l soft links, soft link file permissions are all rwxrwxrwx, but depending on the permissions of the original file
4. Modify any file and change the other one.
5. Delete the original file. Soft links cannot be used.
6. To create a soft link, you must write an absolute path
Note that the file permission of the soft link is 777, but the final permission active file determines that l represents the soft link file.
Once the source file is deleted, the soft link cannot be used. (this is the main difference from hard links)
Note: when creating a soft link, the source file should always use an absolute path, otherwise, if the soft link and the source file are not in the same directory, the source file will not be found. (this is not the case with hard links)
Less restrictions, more flexible, recommended use.
Add:
There are two limitations to hard connections in linux systems: they cannot span file systems and ordinary users are not allowed to hard connect directories. As for the first limitation, it is easy to understand, while the second is not so easy to understand. Using the ls-l command to any directory, you can see that the number of connections is at least 2, which also shows that there is a hard connection in the system, and the command ln-d also allows the superuser to make a hard connection to the directory, which shows that the system restricts hard connection to the directory is only a hard rule, not logically disallowed or technically infeasible. So why does the operating system have entry restrictions? There may be two answers.
First of all, if a hard connection to a directory is introduced, it is possible to introduce a loop in the directory, and the system will fall into an infinite loop when the directory is traversed. You might say that symbolic links can also be introduced into loops, so why not limit symbolic connections to directories? The reason is that in the linux system, each file (directory is also a file) corresponds to an inode structure, in which the inode data structure contains information about file types (directories, ordinary files, symbolic connection files, etc.), that is to say, the operating system can determine symbolic links when traversing directories. Since symbolic links can be judged, some measures can be taken to prevent excessive loops. The system stops traversing after it encounters eight symbolic links in a row, which is why symbolic connections to directories do not enter a dead loop. However, for hard connections, due to the limitations of the data structure and algorithm used in the operation system, we can not prevent this kind of dead cycle at present.
Before explaining the second reason, let's take a look at what the dentry structure of files looks like in system space and how they are stored in system space. The dentry structure mainly contains the file name, the inode number of the file, the pointer to the parent directory dentry structure and some other pointers that have nothing to do with this discussion, the key here is the pointer to the parent directory; all the dentry structures in the system are stored in the hash table according to the hash value, where the hash algorithm is very important, it takes the file name and the address of the file's parent directory dentry structure to hash out the hash value. Now suppose there are two directories / an and / b, where / b is the hard connection to / a that we set up with the ln-d command. At this time, there will be a / a dentry structure and a / b dentry structure in the kernel space. According to the above knowledge, every file or directory under / an and / b directories has its own corresponding dentry structure (because although the file name under the / a directory has not changed, the dentry structure has a pointer to the parent directory dentry and the address of the parent directory dentry structure is taken into account when calculating the hash value. At this time, the dentry structure is not available), and this inheritance will also affect all the files under the subdirectory, which will waste a lot of system space, especially if there are a large number of files and subdirectories in the hard-linked directory. This may be the second reason.
At this point, I believe that everyone on the "Linux files and directories corresponding to the difference between hard links and soft links" have a deeper understanding, might as well to the actual operation of it! 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.