Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 01-16-2007, 08:08 PM   #1
Registered: Mar 2003
Posts: 178

Rep: Reputation: 30
Is there a way to search for and remove dead symbolic links?

I would like to recursively search my system looking for and removing dead symbolic links. Is there a find command I can use that will return all dead links and remove them.
Old 01-16-2007, 08:45 PM   #2
LQ Guru
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 250Reputation: 250Reputation: 250
I remembered this from Advanced Bash Scripting guide and found it:

find /some/dir -type l -print0 | xargs -r0 file | grep "broken symbolic" | sed -e 's/^\|: *broken symbolic.*$/"/g'

At least this will find the broken links, I'm sure from there you can figure out how to remove them, but then again, it's always nice to do a test run before deleting anything when dealing with computers.. especially since /proc and other psuedo filesystems or directories might have symlinks or circular links that might report to be broken but shouldn't be removed.

PS. that l after -type is an L not a pipe.

Last edited by trickykid; 01-16-2007 at 08:47 PM.
Old 01-16-2007, 10:15 PM   #3
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
There is a utility called symlinks that can track them down. Here is the man page for symlinks:
Old 01-18-2007, 03:05 PM   #4
Registered: Mar 2003
Posts: 178

Original Poster
Rep: Reputation: 30

Thank you both for the tips I'll try them out now.
Old 01-18-2007, 05:38 PM   #5
Senior Member
Registered: Apr 2005
Location: OZ
Distribution: Debian Sid
Posts: 4,734
Blog Entries: 12

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462 Project details for KleanSweep
KleanSweep allows you to reclaim disk space by finding unneeded files. It can search for files based on several criteria: you can seek for empty files, backup files, broken symbolic links, dead menu entries, duplicated files, orphaned files (files not found in the RPM or deb database), obsolete thumbnails, and more. Project details for FSlint
FSlint is a toolkit to find various forms of lint on a filesystem. At the moment it reports duplicate files, bad symbolic links, troublesome file names, empty directories, non stripped executables, temporary files, duplicate/conflicting (binary) names, and unused ext2 directory blocks.
Old 01-19-2007, 03:09 AM   #6
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 56
Under Debian I used a tool (rmlinks or something like this, pretty standard) and it fuxored my directories.
I have /usr/share/doc pointing to /xfs/doc (space is lacking) or other weird things (crossing several different filesystems) and it just removed the links! Great.
I'm maybe not using it properly but you should really take care.
Personnaly I don't see the use of this (unless you have hundreds of dead links then you have a problem) and won't use it anymore.

Last edited by nx5000; 01-19-2007 at 03:10 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I remove symbolic links? MichaelZ Linux - Newbie 5 11-19-2009 08:45 AM
How to search for files that are symbolic links pointing to a particular file? Akhran Linux - Newbie 1 10-13-2005 08:32 AM
Bookmark mgr to remove dead links? hyllplan Linux - Software 0 08-31-2005 07:35 AM
Symbolic links bkmesenbrink Linux - Newbie 2 11-13-2002 12:54 PM
Symbolic links Valerie Linux - Newbie 12 03-31-2002 02:49 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:57 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration