sed -n '/%NAME%/{n;h;}; /%SIZE%/ {n;H;x;s/\n/\t/;p;}' /var/lib/pacman/local/*/desc | sort -rnk2
But this is ancient anyways.
]]>cat > pacman_sizes.sh << EOF
#!/bin/sh
pacman -Qi | awk $@ '
BEGIN {
units["B"] = 0
units["KiB"] = 1
units["MiB"] = 2
units["GiB"] = 3
if (unit == "") unit = "MiB"
if (min == "") min = 50
if (pad == "") pad = 10
}
/^Name/ {name=$3}
/^Installed Size/ {
size = (int($4) * 1024^units[$5]) / 1024^units[unit]
if (size > min) printf "% *.1f %s %s\n", pad, size, unit, name
}
' | sort -n
EOF
chmod a+x pacman_sizes.sh
./pacman_sizes.sh -v unit=KiB -v min=100
Not going to sell expac for me, karol?
expac '%m\t%n' | sort -h
Okay expac is ridiculously faster. Everyone use that.
]]>Not going to sell expac for me, karol?
expac '%m\t%n' | sort -h
This is what happens when I post before my first coffee.
I think Allan's script counts size differently.
Not going to sell expac for me, karol?
expac '%m\t%n' | sort -h
Mine is better
]]>expac '%m\t%n' | sort -h
#!/usr/bin/env python2
import subprocess
from itertools import izip
p = subprocess.check_output(["pacman", "-Qi"])
p = p.split("Name")
def sizes():
for i,x in enumerate(p):
try:
yield p[i].split("Installed Size : ")[1].split("\n")[0]
except Exception:
pass
def names():
for i,x in enumerate(p):
try:
yield p[i].split(":")[1].split("\n")[0].strip()
except Exception:
pass
final_list = sorted(((size,name) for size, name in izip(sizes(), names())), key=lambda x: int(x[0].split(".")[0]))
for size, name in final_list:
print "%s has a size of %s" % (name, size)
Another way to do it. Someone was asking for this on IRC so I hacked this together in 10 minutes. It abuses the try, except construct heavily, so please don't take this as being good python. This should be much faster than the original one though.
real 0m0.209s
user 0m0.147s
sys 0m0.030s
Also, the reason I'm bumping this thread is because the older ones might not work anymore, and someone else might benefit from this.
Edit: changed zip to izip, should improve speed for anyone who wants to use it
]]>LC_ALL="C" /usr/bin/pacman -Qi | awk '/^Installed Size/{print int($4), name} /^Name/{name=$3}' | sort -nr
LC_ALL needs to be set, because, with other languages, this produces an empty output.
The absolute path also needs to be set, because users of pacman-color.
Btw. thanks for the script!
return "%d %s" % (self.size, self.name )
pacman -Qi|awk '/^Installed Size/{print int($4), name} /^Name/{name=$3}'|sort -nr
That being said, great job of using python in an OO manner.
One comment on your python code.
return `self.size`+" "+self.name
back quotes are deprecated and will be removed in p3k. p3k changes use repr() instead of that's what you intended.
Here's an example of back quotes, repr(), and str()
>>> import datetime
>>> a=datetime.datetime.now()
>>> repr(a)
'datetime.datetime(2008, 3, 30, 13, 12, 29, 664490)'
>>> `a`
'datetime.datetime(2008, 3, 30, 13, 12, 29, 664490)'
>>> str(a)
'2008-03-30 13:12:29.664490'
>>> print `a`
datetime.datetime(2008, 3, 30, 13, 12, 29, 664490)
>>> print a
2008-03-30 13:12:29.664490
Thanks - that's very useful and it is a nice gentle introduction to Python for me!
]]>I posted an update of my libalpm example there :
http://bbs.archlinux.org/viewtopic.php?id=42707
it will just output a list of your packages, sorted by size, starting from the largest, to the standard output
the output is in format
272495 openoffice-base
138817 tetex
115541 acroread
102316 jre
95587 jdk
65836 kernel26
65649 wine
...
for example
here is the script:
#!/usr/bin/env python
import re
import os
class Package:
def __init__(self,name,size):
self.name = name
self.size = int(round(float(size)))
def __repr__(self):
return `self.size`+" "+self.name
def __cmp__(self,other):
return cmp(other.size,self.size) #desc
paclist = []
re_name = re.compile(r'Name\s*:\s*(\S+)')
re_size = re.compile(r'Installed Size\s*:\s*([0-9.]+).*')
p = os.popen("pacman -Qi","r")
for line in p.readlines():
match_name = re_name.match(line)
match_size = re_size.match(line)
if match_name :
package_name = match_name.groups(1)[0]
if match_size :
package_size = match_size.groups(1)[0]
paclist.append(Package(package_name,package_size))
p.close()
paclist.sort()
for pac in paclist: print pac
I called it "pacsize".
alternatively you can download it here
]]>