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/01 Report--
This article mainly explains "how to find and delete broken symbolic links on 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 how to find and delete broken symbolic links on Linux.
Symbolic links are Linux files that point to another file. If the referenced file is deleted, the symbolic link will be retained, but it will not show a problem unless you try to use it. Here is an easy way to find and delete symbolic links that point to files that have been deleted.
Symbolic link symbolic link plays a very useful role on Linux systems. They can help you remember the location of important files on your system, make it easier for you to access them, and save you a lot of space by not having to copy them for easier access to large files.
What is a symbolic link?
They are often called "symbolic links" or "soft links", and symbolic links are very small files. In fact, a symbolic link really contains the name of the file it points to, usually containing a path (relative to the current location or absolute path). If a file named ref1 points to a file named / apps/refs/ref-2020, the ref1 will be 19 characters long, even if the ref-202 file has 2TB. If you point to. / ref-2020, the length is only 10 characters. If you point to ref-2020, there are only 8 bytes.
If you execute commands such as vi ref1 (where ref1 is the name of the symbolic link), you will edit the file that ref1 points to, not the contents of the symbolic link itself. The Linux system knows how to use symbolic links and can do the right thing. Similarly, if you use commands such as cat, more, head, or tail, you will look at the contents of the referenced file.
On the other hand, if you delete a symbolic link, you will delete the link instead of the referenced file. Again, Linux knows what to do. Symbolic links make it easier to use and share files, that's all.
When a symbolic link is damaged
When a file that a symbolic link points to is deleted or renamed from the system, the symbolic link no longer works. A symbolic link is simply a reference stored in a particular directory, and it is not updated or deleted as the file pointing to it changes. It always points to the referenced file, even if the file is long gone.
If you try to use a symbolic link to a file that does not exist, the following error occurs:
$tail whassuptail: cannot open 'whassup' for reading: No such file or directory
If you try to access a symbolic link to yourself (yes, something strange has happened), you will see something similar to the following:
$cat loopycat: loopy: Too many levels of symbolic links$ ls-l loopylrwxrwxrwx 1 shs shs 5 May 28 18:07 loopy-> loopy
And if the first letter of the long list doesn't get your attention, it means the file is a symbolic link. Rwxrwxrwx permissions are standard permissions and do not reflect the permissions of the file that the symbolic link points to.
Find broken symbolic links
The find command has an option that allows you to find symbolic links to files that no longer exist. This command lists symbolic links in the current directory:
$find. -type l
L (lowercase L) tells the find command to look for symbolic links.
On the other hand, the following command looks for symbolic links to files that do not exist in the current directory:
$find. -xtype l
To avoid errors when the command tries to find files or directories that you don't have permission to check, you can output all errors to / dev/null, as shown below:
$find. -xtype l 2 > / dev/null
You can also use this command to find broken symbolic links. It's longer than the previous one, but it does the same thing:
$find. -type l!-exec test-e {}\;-print 2 > / dev/null how to handle broken symbolic links
Unless you know that the file referenced by the symbolic link will be replaced, the best way is to delete the damaged link directly. In fact, if necessary, you can use a command to find and remove broken symbolic links, such as:
$find. -xtype l 2 > / dev/null-exec rm {}\
The rm {} part of the command becomes the "delete file" command
If you want to associate a symbolic link with a different file, you must first delete the symbolic link and then recreate it to point to the new file. This is an example:
$rm ref1 $ln-s / apps/data/newfile ref1 summary
Symbolic links make referenced documents easier to find and use, but sometimes they go too far than road signs that advertise restaurants that were closed last year. The find command can help you get rid of broken symbolic links, or remind you that there are no files you may still need.
At this point, I believe you have a deeper understanding of "how to find and delete damaged symbolic links on 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.