You are not logged in.

#1 2007-02-04 20:42:15

Galdona
Member
Registered: 2006-03-15
Posts: 196

how about a script to clean up /var/cache/pacman/pkg

/var/cache/pacman/pkg can get filled up with packages that you intalled once, just to try out, but then uninstalled and never plan to install again. I am thinking of a script that removes pkg.tar.gz's that are not installed, which will clear up some truly "dead" space on your hard drive. What do you think?

Offline

#2 2007-02-04 21:23:42

stonecrest
Member
From: Boulder
Registered: 2005-01-22
Posts: 1,190

Re: how about a script to clean up /var/cache/pacman/pkg

pacman -Sc and pacman -Scc


I am a gated community.

Offline

#3 2007-02-04 21:46:14

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: how about a script to clean up /var/cache/pacman/pkg

No... I have read the pacman manpage, thank you very much.

I guess my first post lacks explanation. I don't want to do pacman -Scc, but I want to remove ... oh man just read my first post. I still want to keep the pkg.tar.gz's which are currently installed.

Offline

#4 2007-02-04 21:49:53

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: how about a script to clean up /var/cache/pacman/pkg

For example, I have already uninstalled xfce, but pacman -Sc will not remove the most recent xfce pkgs in /var/cache/pacman/pkg, and I don't want to do pacman -Scc either.

Right now it would have to be done manually.

(Sorry if this is not a "contribution"; I guess my "contribution" is the idea...)

Last edited by Galdona (2007-02-04 21:55:19)

Offline

#5 2007-02-04 22:49:32

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: how about a script to clean up /var/cache/pacman/pkg

now, now, no need to get so exasperated.   I whipped up a quick script that'll do the job for you:

-- edit -- Er.. script had a bug that may make it remove more packages than expected.  I'll fix and repost in one sec. -- /edit --

Last edited by Cerebral (2007-02-04 22:52:16)

Offline

#6 2007-02-04 23:01:03

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: how about a script to clean up /var/cache/pacman/pkg

O gee that would be really nice! smile smile smile

Offline

#7 2007-02-04 23:11:32

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: how about a script to clean up /var/cache/pacman/pkg

There, this should be a 'fixed' version.  smile  As always, use at own risk.

#!/bin/bash

for pkgname in $(ls /var/cache/pacman/pkg/ | sed "s#\(.*\)-.*-.*#\1#g" | sort | uniq ); do
    pacman -Q $pkgname 2>/dev/null >/dev/null
    if [ $? -ne 0 ]; then
        echo "$pkgname in cache but not installed, removing."
        pkgs=$(ls /var/cache/pacman/pkg/$pkgname-* | grep -e "$pkgname-[0-9]")
        rm $pkgs
    fi
done

Offline

#8 2007-02-04 23:51:00

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: how about a script to clean up /var/cache/pacman/pkg

I'm afraid to try it! Your disclaimer hints at some uncertainty...
Anyway, the worst that can happen is I lose all cached pkgs... right?
Alright, I'll try it a bit later!

Offline

#9 2007-02-04 23:54:42

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: how about a script to clean up /var/cache/pacman/pkg

shall we name it... ccup? (Clear Cache of Uninstalled Packages) tongue

Offline

#10 2007-02-05 00:20:58

dyzdyz
Banned
Registered: 2007-01-22
Posts: 20

Re: how about a script to clean up /var/cache/pacman/pkg

I once asked same question. As an answer maniel quickly wrote this script, which does the job. It requires ruby. Works for me, but NO WARRANTY, use it at your own risk.

ls /var/cache/pacman/pkg/ |ruby -wne 'x=$_.split(/-/)[0..-3].join("-"); `pacman -Qi #{x} &>/dev/null`; `rm /var/cache/pacman/pkg/#{$_}` if $?!=0'

Offline

#11 2007-02-05 01:24:18

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: how about a script to clean up /var/cache/pacman/pkg

I usually use this script:

#!/bin/bash
for i in $(ls -1 /var/cache/pacman/pkg);do j=${i%-*};pacman -Q ${j%-*}|grep found;done

It doesn't remove anything. It just list the pkgname.

Offline

#12 2007-02-05 03:10:46

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: how about a script to clean up /var/cache/pacman/pkg

Haha I only just now saw the output of pacman -V. cute!

It would be nice to have the above-discussed functionality included in pacman3. eherm.

Offline

#13 2007-02-05 03:23:04

McQueen
Member
From: Arizona
Registered: 2006-03-20
Posts: 387

Re: how about a script to clean up /var/cache/pacman/pkg

A script posted previously:

#!/bin/bash 
##Remove packages from cache not installed
#and download any installed pkgs not cached

pacman -Sc 

pacman -Q | sed s/' '/-/g > /tmp/installed 


for pkg in `ls /var/cache/pacman/pkg` 
do 
        name=${pkg%%.pkg.tar.gz} 
        if [[ ! `grep $name /tmp/installed` ]] 
        then 
                echo Removing $name 
                rm -f /var/cache/pacman/pkg/$pkg 
        fi 
done 

pacman -Q | cut -d ' ' -f 1 > /tmp/installed 
pacman -Sl | cut -d ' ' -f 2 >> /tmp/installed 

pacman -Sw `sort /tmp/installed | uniq -d`

/path/to/Truth

Offline

#14 2007-02-05 03:26:34

toofishes
Developer
From: Chicago, IL
Registered: 2006-06-06
Posts: 602
Website

Re: how about a script to clean up /var/cache/pacman/pkg

One of my goals for Pacman 3.1 is to implement some more cache-cleaning functionality, including ensuring the installed version of a package is not removed (currently only the newest version is kept, whether or not it is installed). However, this will take some reworking of the pacman internals to make it easier to implement, so it will not likely make it into the first release of pacman 3.

Offline

#15 2007-02-11 02:14:07

picpak
Member
Registered: 2006-12-02
Posts: 89

Re: how about a script to clean up /var/cache/pacman/pkg

Well, I would just put pacman -Scc in my /etc/rc.local, but these solutions are a lot more cleaner than that.


Regards,
Picpak

Offline

#16 2007-02-11 03:22:29

Galdona
Member
Registered: 2006-03-15
Posts: 196

Re: how about a script to clean up /var/cache/pacman/pkg

picpak wrote:

Well, I would just put pacman -Scc in my /etc/rc.local, but these solutions are a lot more cleaner than that.

You *totally* did not read the entire thread.

Last edited by Galdona (2007-02-11 03:32:32)

Offline

#17 2007-02-11 16:07:51

picpak
Member
Registered: 2006-12-02
Posts: 89

Re: how about a script to clean up /var/cache/pacman/pkg

Yeah I did, that's why I said that these solutions are a lot more cleaner than that.


Regards,
Picpak

Offline

#18 2007-02-11 20:03:30

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: how about a script to clean up /var/cache/pacman/pkg

you could also try pajman. It is a script that i wrote that also performs package name based searches at light speed.

Offline

#19 2007-02-11 21:44:37

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: how about a script to clean up /var/cache/pacman/pkg

I have another alternative; my /var/cache/pacman/pkg is mounted by many clients to save diskspace. This means I cannot simply check if it is installed locally; since another machine might have it installed. I use the following script to check if the version in the cache is the latest version. If it is not, I assume it is not being used anywhere [my machines frequently update, so that should work fine] and then delete it. Also; if it would be in use anywhere that doesn't matter since the old version won't be used anyway

Here is the script:

for f in $(ls /var/cache/pacman/pkg);do p=${f%-*};p=${p%-*};v=${f/#$p-/};v=${v/%\.pkg\.tar\.gz/}; pacman -Si $p 2>/dev/null|grep -q $v || rm -v /var/cache/pacman/pkg/$f; done

Last edited by Spider.007 (2007-03-08 08:40:28)

Offline

#20 2008-08-24 04:55:33

munkyeetr
Member
From: Merritt, BC
Registered: 2008-08-07
Posts: 83

Re: how about a script to clean up /var/cache/pacman/pkg

Cerebral wrote:

There, this should be a 'fixed' version.  smile  As always, use at own risk.

#!/bin/bash

for pkgname in $(ls /var/cache/pacman/pkg/ | sed "s#\(.*\)-.*-.*#\1#g" | sort | uniq ); do
    pacman -Q $pkgname 2>/dev/null >/dev/null
    if [ $? -ne 0 ]; then
        echo "$pkgname in cache but not installed, removing."
        pkgs=$(ls /var/cache/pacman/pkg/$pkgname-* | grep -e "$pkgname-[0-9]")
        rm $pkgs
    fi
done

Sorry to ressurect such an old thread, but I just came across this and the script above worked great for me; cleared over 700MB from my .../pacman/pkg directory. I am curious though, why we want to keep the tar.gz's of installed programs in the cache. If the program is already installed, what purpose do they serve there? Just curious...


If the advice you're given in this forum solves your issue, please mark the post as [SOLVED] in consideration to others.

"More than any time in history mankind faces a crossroads. One path leads to despair and utter hopelessness, the other to total extinction.
Let us pray that we have the wisdom to choose correctly." -- Woody Allen

Offline

#21 2008-08-25 02:47:14

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 185

Re: how about a script to clean up /var/cache/pacman/pkg

Arch, currently, doesn't have a unique packaging suffix (such as .deb or .rpm), it just uses the following scheme:

packagename-version-revision-architecture.pkg.tar.gz

The way to package Arch applications is to install them to a fakeroot directory and tar it.  The resulting pkg.tar.gz does not contain the original source code, but rather the application's files that have been compiled and organized for your specific architecture.

When you install a package with Pacman, its pkg.tar.gz is downloaded to /var/cache/pacman/pkg and unpacked to your root ( / ) directory.  The tarball is left in your cache in case you need to (re)install it without having to (re)download it.  It's also handy to have an older version of a package readily available in case a newer one doesn't work well.


Dylon

Offline

#22 2008-08-25 05:05:39

munkyeetr
Member
From: Merritt, BC
Registered: 2008-08-07
Posts: 83

Re: how about a script to clean up /var/cache/pacman/pkg

oh okay, so they aren't necessary to keep, and they're never used unless you want to reinstall a program.

thank you.


If the advice you're given in this forum solves your issue, please mark the post as [SOLVED] in consideration to others.

"More than any time in history mankind faces a crossroads. One path leads to despair and utter hopelessness, the other to total extinction.
Let us pray that we have the wisdom to choose correctly." -- Woody Allen

Offline

#23 2008-11-05 16:17:39

erythrocyte
Member
Registered: 2008-10-21
Posts: 25

Re: how about a script to clean up /var/cache/pacman/pkg

hi, i'm a noob at Arch and having trouble understanding the difference between 'pacman -Sc' and the aforementioned script... when do i need to use which?

doesn't pacman -Sc wipe off packages that i have uninstalled?

Offline

#24 2008-11-05 16:33:37

erythrocyte
Member
Registered: 2008-10-21
Posts: 25

Re: how about a script to clean up /var/cache/pacman/pkg

i'm not sure if this info still applies to pacman, since it's been updated from version 3.0, but a very helpful individual (MrElendig) on the #archlinux irc channel clarified on the utility of the script. i'm pasting it here:

(21:51:54) MrElendig: erythrocyte: example:
(21:52:05) MrElendig: you have 2 apps  foo and bar
(21:52:12) MrElendig: you installed foo1 and bar 1
(21:52:23) MrElendig: then you upgraded to foo2 and bar2
(21:52:32) MrElendig: then you -R bar
(21:52:49) MrElendig: if you -Sc then that will remove foo1, bar1 and bar2
(21:53:03) MrElendig: if you use the script, only bar1 and bar2 will be removed

hope that clears up a few doubts for users new to Arch linux

Offline

#25 2008-12-19 02:10:00

handy
Member
From: Oz
Registered: 2008-03-26
Posts: 719

Re: how about a script to clean up /var/cache/pacman/pkg

munkyeetr wrote:

oh okay, so they aren't necessary to keep, and they're never used unless you want to reinstall a program.

thank you.

Sometimes a package will cause trouble, which is easily escaped by downgrading.  If you have trouble that brakes your internet connection it is so easy to fix by referring to your /var/log/pacman.log (if you have to) & downgrading, using the following method from the Arch Wiki:

You may be able to downgrade the package trivially by visiting /var/cache/pacman/pkg/ on your system and seeing if the older version of the package is stored there. (If you haven't run pacman -Scc recently, it should be there). If the package is there, you can install that version using pacman -U pkgname-olderpkgver.pkg.tar.gz. If pacman complains about file conflicts, you could force it to do the installation anyway with pacman -Uf pkgname-olderpkgver.pkg.tar.gz.

We had a kernel bug last October that caused many who did not have a copy of a previous kernel in their cache some extra trouble &  education. ;-)

If you ever need a superseded kernel have a look here:

http://ubuntuforums.org/showthread.php?t=954481

Last edited by handy (2008-12-19 02:10:46)


I used to be surprised that I was still surprised by my own stupidity, finding it strangely refreshing.
Well, now I don't find it refreshing.
I'm over it!

Offline

Board footer

Powered by FluxBB