LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 10-01-2003, 01:30 PM   #1
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Dead sym links


I'm trying to get Sentinel installed on my box, and the initialization keeps tripping over dead sym links. Is there a way to globally delete the dead links or do I need to do it one link at a time?
 
Old 10-01-2003, 01:48 PM   #2
ehdwuld
Member
 
Registered: Jul 2003
Distribution: Currently Suse 11.1 but have RH7,8,9 / Fedora 7,8_64,9_64,&10_64
Posts: 634

Rep: Reputation: 30
um
imho
global commands and doing things " in masse"
are a little scary
cuase you have to be root to make such sweeps



one typo

and whammo

losts o stuff broke
 
Old 10-01-2003, 05:15 PM   #3
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803

Original Poster
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Quote:
one typo

and whammo

losts o stuff broke
Well, yeah.....That is the fun of linux. We are all just one rm * -rf away from a nice, clean hard disk.

In this case however, I'm trying to find broken sym links. Since the target of the link is no longer there, if I delete the link there should be no loss.
 
Old 10-01-2003, 06:38 PM   #4
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
This after *cough* very limited testing seems to do the job if that's what you're meaning

Code:
#!/bin/bash


#cd to the top-level directory you are searching

fileList=`find -type l`

for i in $fileList
do

if [ -f  $i ]
 then
   echo "$i still points to a file"
 else
   echo "$i no longer points to a file"
#uncomment to delete   rm $i
 fi

done
 
Old 10-01-2003, 08:39 PM   #5
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803

Original Poster
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Many, many thanks Looking_Lost, that is exactly what I was looking for!

<edit>
I did a bit more testing and for links pointing to files, it works perfectly. However, when the link points to a directory, the script correctly decides that the link does not point to a file and removes it, even though the directory exists.

In the end, I dumped the output to a file and investigated before I deleted.

Again, many thanks Looking_Lost
</edit>

Last edited by Hangdog42; 10-01-2003 at 08:49 PM.
 
Old 10-02-2003, 04:35 AM   #6
Looking_Lost
Senior Member
 
Registered: Apr 2003
Location: Eire
Distribution: Slackware 12.0, OpenSuse 10.3
Posts: 1,120

Rep: Reputation: 45
Yeah, it could be quite dangerous as it could end up deleting links to other types of files without further checking so I definitely wouldn't run it on / , but do what you did output, it's results to a file but the basic idea is there.
 
  


Reply



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
Sym links and hard links akudewan Linux - Newbie 4 02-09-2005 05:08 AM
sym links -- RealPlayer lmellen Linux - Newbie 2 08-29-2004 02:29 PM
history of links on boxs (sym and otherwise) ergo_sum Linux - Newbie 1 10-31-2003 04:27 PM
Sym Links and vsFTPd Datacraft Linux - Software 1 05-24-2003 05:20 PM
dead sym links dewcansam Linux - General 1 02-08-2002 04:49 PM

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

All times are GMT -5. The time now is 09:21 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
Open Source Consulting | Domain Registration