In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you the introduction of hard links and soft links in Linux, and analyze and describe them from a professional point of view. I hope you can get something after reading this article.
Hard link
First of all, let's look at hard links, and let's compare them with references to variables in php.
$a = 100 * b = & $a
You can think of $an as a file, while $b sees a hard link to a file. The effect now is that whether $an or $b is modified, it will affect the other party.
If you delete one of the files now, does the other still exist?
Unset ($b)
Even if the $b file is deleted, the $a file still exists.
Next, let's see if it is the same as mentioned above. The command to create a hard link is as follows:
Ln source file link file
At present, the system has a 1.php file, now let's create a hard link for it.
# ln 1.php 2.php# cat 1.php
As you can see, if you modify the 2.phpd1.php file, it will also be modified. Now let's delete the 2.php file and see if the 1.php file still exists.
# rm-f 2.php# ll 1.phpMurr RWMurray Rafael-1 root root 52 Jun 20 08:05 1.php
As you can see, even if you delete the 2.php dint 1.php file, it still exists.
The role of hard links is described above, and the restrictions on the use of hard links are described below:
Cannot link directory
Cannot make links across file systems
Due to the above two limitations, there are few opportunities for daily use of hard links, here is another kind of link-soft links, it does not have the above restrictions, so usually use a lot of oh!
Soft link
Soft links are generally compared with desktop shortcuts in windows systems. By creating soft links, you can easily execute a command without looking for the directory location of the file. In addition, the soft link file is deleted and the source file still exists. However, if the source file is deleted, the linked file has no effect.
Soft links are divided into files and directories. The functions of these two kinds of links are described below.
Make a soft link to a file
Have you ever wondered why after you have installed mysql, you can use mysql instead of using an absolute path. Soft links are used in this.
# which mysql/usr/bin/mysql# ll / usr/bin/mysqllrwxrwxrwx 1 root root 26 Nov 4 2019 / usr/bin/mysql-> / usr/local/mysql/bin/mysql
As you can see, the actual address of the command is / usr/local/mysql/bin/mysql, but the file is softly linked to the / usr/bin/ directory, so you don't have to use an absolute path to invoke the command.
Let's make a file soft link by ourselves to see if this is the case.
First create a file soft.sh
Vim softpowered soft Binder Backecho 'study softlink'# chmod upright x
Then create a soft link to the file to see if it is okay to execute the command directly
# ln-s / root/soft / usr/bin/# softstudy softlink
Make soft links to the directory
First of all, we need to note that when doing soft links, the target file or directory must not exist.
Next, let's introduce a scenario, which is very common:
The website files are stored in the / www/wwwroot directory, which gets bigger and larger as the system runs worse and worse, and because the directory is in the same partition as the root directory, the root directory is about to be full. The other partition directory / data has 99 gigabytes of space left. At this point, you don't want to repartition, so what do you need to do to liberate the partition where the root directory resides?
Next, we use directory soft links to solve this problem. First, create the wwwroot directory under the / data directory, then move all the files under the / www/wwwroot directory to / data/wwwfile, and then delete the / www/wwwroot directory. Finally, give the / data/wwwfile directory soft link to / www/wwwroot
Mkdir / data/wwwfilemv / www/wwwroot/* / data/wwwfilerm-rf / www/wwwrootln-s / data/wwwfile / www/wwwroot
Now, let's test whether the problem is really solved. Currently, the root partition utilization is 19%, while the / data partition utilization is 9%.
/ dev/vda1 40G 7.4G 33G 19% / / dev/vdb1 500G 43G 458G 9% / data
Let's create a large 2G file in the / www/wwwroot directory and see which partition has become larger. The answer we want is that the / data partition usage is higher, while the root partition remains the same.
Dd if=/dev/zero of=/www/wwwroot/bigfile bs=1G count=2# then looks at the changes in capacity of each partition / dev/vda1 40G 7.4G 33G 19% / / dev/vdb1 500G 45G 456G 9% / data
As you can see, the available capacity of the root partition is still 33g, but the / data partition has changed from 458g to 456g, so we solved the problem.
The above is the hard link and soft link in Linux that Xiaobian shared for you. After reading, do you have a further understanding of hard link and soft link? If you want to know more about it, please follow the industry information.
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.