Find broken Links

Written by Benjamin Cane on 2011-08-19 20:32:06

At the end of the day this is easier than I expected.

Example:

[[email protected] play]# find ./ -follow -lname "*"  
./somedir4  
./somedir7  
./somedir6  
./somedir5  
[[email protected] play]# ls -la  
total 12  
drwxrwxr-x. 3 bcane bcane 4096 Aug 15 18:35 .  
drwxrwxrwt. 4 root root 4096 Aug 15 18:28 ..  
drwxr-xr-x. 2 bcane root 4096 Aug 15 18:42 somedir  
lrwxrwxrwx. 1 root root 7 Aug 15 18:35 somedir1 -> somedir  
lrwxrwxrwx. 1 root root 7 Aug 15 18:35 somedir2 -> somedir  
lrwxrwxrwx. 1 root root 7 Aug 15 18:35 somedir3 -> somedir  
lrwxrwxrwx. 1 root root 10 Aug 15 18:35 somedir4 -> somedir_no  
lrwxrwxrwx. 1 root root 10 Aug 15 18:35 somedir5 -> somedir_no  
lrwxrwxrwx. 1 root root 10 Aug 15 18:35 somedir6 -> somedir_no  
lrwxrwxrwx. 1 root root 10 Aug 15 18:35 somedir7 -> somedir_no

Once you've found the broken links you can delete them easily.

[[email protected] play]# find ./ -follow -lname "*" -delete  
[[email protected] play]# ls -la  
total 12  
drwxrwxr-x. 3 bcane bcane 4096 Aug 15 18:43 .  
drwxrwxrwt. 4 root root 4096 Aug 15 18:28 ..  
drwxr-xr-x. 2 bcane root 4096 Aug 15 18:42 somedir  
lrwxrwxrwx. 1 root root 7 Aug 15 18:35 somedir1 -> somedir  
lrwxrwxrwx. 1 root root 7 Aug 15 18:35 somedir2 -> somedir  
lrwxrwxrwx. 1 root root 7 Aug 15 18:35 somedir3 -> somedir

comments powered by Disqus
Picture of Benjamin Cane

Benjamin is a Systems Architect working in the financial services industry focused on platforms that require Continuous Availability. He has been working with Linux and Unix for over 10 years now and has recently published his first book; Red Hat Enterprise Linux Troubleshooting Guide.

Publications

Identify, capture and resolve common issues faced by Red Hat Enterprise Linux administrators using best practices and advanced troubleshooting techniques

What people are saying:
Red Hat Enterprise Linux Troubleshooting Guide may just be all you need in your quest to wear the red hat. - Perry N.
Buy on Amazon

Sponsored by