(?) The Answer Gang (!)


By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and the Gang, the Editors of Linux Gazette... and You!
Send questions (or interesting answers) to linux-questions-only@ssc.com

There is no guarantee that your questions here will ever be answered. You can be published anonymously - just let us know!


(?) How can you do a recursive search to find broken symbolic links?

From bandido

Answered By Ben Okopnik, Faber Fedor, Mike Orr

(?) I found the odd broken link after a few upgrades, and was wondering how can I hunt down any other such beasties, 'ls' doesn't have any suitable way to delimit, and poking about in man pages for find etc made me quite nautious.

(!) [Faber] Perhaps you should take some Dramamine. :-) The man pages are you friend. If you do a "man find" and then type "/link" (that will do a search on the word link) you'll find all kinds of references to the work "link" (the owrk "link" will be highlighted). Scroll down a couple of pages and you'll find the "type" option.
So, to find all the links on your system, you would type

find / -type l
Simple, no? :-)
(!) [Ben] No. The querent was asking how to find broken links, not all links.
What's needed here is the "symlinks" program, written by Mark Lord. It will find and classify all the links, hard and soft, in the filesystem. If you want to see all the dangling (i.e., broken) links on your system, just type

symlinks -r / | grep ^dangling # Recursive search starting from /
If you want to delete all the broken ones, just enter

symlinks -dr / # Recurse and delete broken links starting from /
For me personally, this wouldn't work too well. I use dangling links as placeholders; as an example, I've disabled NFS during the boot procedure by "breaking" the symlink in "/etc/rc2.d":

S19nfs-common -> ../init.d/nfs-common # Original link

S19nfs-common -> ../init.d/nfs-commonXXX # Dangling!
If I should need to restore NFS, a 5-second fix will do it, without having to figure out what directory the link should go into, where in the process it should load (as determined by the number after the 'S'), or where it should point.

(?) Thank you Ben, and others, a google search found "symlinks", although it only appears to be available for Debian.

(!) [Ben] You could use the "alien" utility to convert it, or simply go to Debian's page for "symlinks" -
<http://packages.debian.org/stable/utils/symlinks.html>;
They always provide a link to the tarball from which the package was made, and you can compile it yourself. <grin> I like Debian. A lot.
(!) [Mike] Or, if you don't have the symlinks program available:
( find / -type l | xargs file ) | grep 'broken symbolic link'

(?) The symlinnks prog worked a charm, indeed ot cleaned up everything nicely, changing absolute to relative links too, lovely.

The real issue, is my rampant stupidity, since after downloading symlinks, lo and behold, I discovered it is part of Mandrake 7.2 which I use.

I had pissed about pouring over man pages trying to find out how to delimit a search to find the buggers, only to discover my salvation was close at hand.

I have received several TAG replies, and I must say the 1st was within 45 minutes. Astounding :)

(!) [Heather] I'll say it's astounding. Some people don't get answers for weeks... if at all...

(?) Keep it up guys.

-- Merp!


This page edited and maintained by the Editors of Linux Gazette Copyright © 2001
Published in issue 65 of Linux Gazette April 2001
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/


[ Table Of Contents ][ Answer Guy Current Index ] greetings   1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29 [ Index of Past Answers ]