Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
remove dead links
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
xo
n00b
n00b


Joined: 16 Oct 2003
Posts: 52

PostPosted: Fri Nov 26, 2004 4:38 pm    Post subject: remove dead links Reply with quote

here's the scenario:
Every couple of months or whenever my harddisk is getting full i ckeck /usr/portage/packages/All for duplicate/old packages and i delete them.
This leaves a ton of orphaned links in directories under usr/portage/packages

So I wrote a small script to remove them all. Hope you find it useful. here it is
Code:
#!/bin/bash

#script do delete dead links
#designed to remove dead links from the /usr/portage/packages directory hierarchy
if [ "$(pwd)" != "/usr/portage/packages" ]; then
   echo "are you sure (y/n)"
   read answer
   if [ "$answer" != "y" ]; then
      exit
   fi
fi

for i in $(ls -d [a-z]*);
do
    if test -d $i; then
   pushd $i
   for j in $(ls);
   do
      if ! test -e $(readlink $j); then
         rm $j
      fi
   done
   popd
    fi
done

_________________
TyanTigerMP | GeForce2MX200 | AudigyPlatinum | PromiseUltra100TX2 | Realtek8139
Back to top
View user's profile Send private message
pjp
Administrator
Administrator


Joined: 16 Apr 2002
Posts: 18107

PostPosted: Mon Nov 29, 2004 3:21 pm    Post subject: Reply with quote

An alternative...
Code:
#!/bin/bash
find /usr/portage/packages -xtype l -print0 |xargs -0 rm

_________________
Those who know what's best for us must rise and save us from ourselves.
Back to top
View user's profile Send private message
urcindalo
Guru
Guru


Joined: 08 Feb 2005
Posts: 594
Location: Almeria, Spain

PostPosted: Tue May 09, 2006 10:29 am    Post subject: Reply with quote

And what about printing out a list of all dead links in the system, starting from /, so that you can later delete which you want?

Thanks in advance.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum