LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-16-2007, 07:08 PM   #1
HGeneAnthony
Member
 
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, 07:45 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 245Reputation: 245Reputation: 245
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 07:47 PM.
 
Old 01-16-2007, 09:15 PM   #3
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,907

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
There is a utility called symlinks that can track them down. Here is the man page for symlinks:

http://www.linuxcommand.org/man_pages/symlinks8.html
 
Old 01-18-2007, 02:05 PM   #4
HGeneAnthony
Member
 
Registered: Mar 2003
Posts: 178

Original Poster
Rep: Reputation: 30
Reply

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

Rep: Reputation: 462Reputation: 462Reputation: 462Reputation: 462Reputation: 462
freshmeat.net: Project details for KleanSweep
Quote:
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.

freshmeat.net: Project details for FSlint
Quote:
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, 02:09 AM   #6
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
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 02:10 AM.
 
  


Reply


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 07:45 AM
How to search for files that are symbolic links pointing to a particular file? Akhran Linux - Newbie 1 10-13-2005 07:32 AM
Bookmark mgr to remove dead links? hyllplan Linux - Software 0 08-31-2005 06:35 AM
Symbolic links bkmesenbrink Linux - Newbie 2 11-13-2002 11:54 AM
Symbolic links Valerie Linux - Newbie 12 03-31-2002 01:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:03 PM.

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