Simply get rid of your old crufty packages (one liner)

Aaron Haviland orion at parsed.net
Mon Aug 20 12:10:01 BST 2007


Kristian Erik Hermansen wrote, on Aug 19, 2007 at 23:39 EDT:
> This is kind of a hack for people who have upgraded from release to
> release and have lots of old package cruft lying around.  Basically,
> over time, packages will be removed from Ubuntu's repositories and/or
> become unmaintained externally in other repositories.  To deal with
> this, and since I have been upgrading like this from Warty -> Hoary ->
> Breezy -> Dapper -> Edgy -> Feisty -> Gutsy merely using 'aptitude
> update && aptitude dist-upgrade', I had much lying around :-)
> 
> This is the one liner...with no error checking or anything, but you
> get the idea.  Use 'remove' to be safe, rather than 'purge', or else
> you will lose any configs you may want to keep for some reason...
> 
> $ sudo -i
> # while true; do aptitude -s reinstall ~i 2>&1 | grep "able to locate
> file for the" | aptitude -y remove $(awk '{print $10}'); done


I find "aptitude -s" doesn't do the trick... it doesn't simulate enough
on my system to go as far as to tell me it can't find the missing debs.

Also, it doesn't seem to work in the case where you have a higher
numbered version installed than the currently available one.

Actually... it doesn't even seem to work for any packages that have a
pending upgrade, either...

Here's a one-liner that works for me, though:

REMOVE_LIST="$(for i in $(dpkg -l|grep ^ii | cut -f3 -d' '); do if [[ "$(apt-cache show $i | grep "^Filename: ")x
" = "x" ]]; then echo -n "${i} " ; fi; done)"; echo "I want to remove: ${REMOVE_LIST}"; sudo aptitude remove $REM
OVE_LIST

(or for better reading in case you want to understand it... and I encourage that!)

REMOVE_LIST="$(                                                                         \
        for i in $(dpkg -l|grep ^ii | cut -f3 -d' ');                                   \
                do                                                                      \
                        if [[ "$(apt-cache show $i | grep "^Filename: ")x" = "x" ]];    \
                                then echo -n "${i} " ;                                  \
                        fi;                                                             \
                done                                                                    \
        )";                                                                             \
echo "I want to remove: ${REMOVE_LIST}";                                                \
sudo aptitude remove $REMOVE_LIST

Just make a handy alias in your .bashrc, or throw it in a script in /usr/local/sbin

One thing I like is that it only uses root (sudo) for the actual removal
of the package, and not for anything else) 

-- 
Aaron Haviland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/ubuntu-us-ma/attachments/20070820/d9c11426/attachment.pgp 


More information about the Ubuntu-us-ma mailing list