You are not logged in.
Hi,
I spend few hours today to make bash script, that allow me get total size of installed packages on my disk. It may be useful for many users.
Here it is:
#!/bin/bash
total=0
progress="-"
count=`pacman -Q | wc -l`
echo "Reading info of "$count" packages reported by 'pacman -Q'.
This may take few minutes..."
for pkg in `pacman -Q | sed 's/\ .*//'`
do
s=`pacman -Qi $pkg | sed -e '/Installed\ Size/!d; s/Installed\ Size\ :[\ ]*//; s/\ K//; s/,/./'`
if [ "$s" != "" ]; then
total=`echo $total" + "$s | bc`
printf "\033[1D"$progress
if [ "$progress" == "|" ]; then progress="-"; fi;
if [ "$progress" == "\\" ]; then progress="|"; fi;
if [ "$progress" == "_" ]; then progress="\\"; fi;
if [ "$progress" == "/" ]; then progress="_"; fi;
if [ "$progress" == "-" ]; then progress="/"; fi;
fi
done
echo
echo "Total size of installed packages is "$total" K"! Script requere bc command (pacman -S bc) !
Thank you for corrections and comments.
Offline
I added a crude human-readability block near the end.
#!/bin/bash
total=0
progress="-"
count=`pacman -Q | wc -l`
echo "Reading info of "$count" packages reported by 'pacman -Q'.
This may take few minutes..."
for pkg in `pacman -Q | sed 's/\ .*//'`
do
s=`pacman -Qi $pkg | sed -e '/Installed\ Size/!d; s/Installed\ Size\ :\ *//; s/\ K//; s/,/./'`
if [ "$s" != "" ]; then
total=`echo $total" + "$s | bc`
printf "\033[1D"$progress
if [ "$progress" == "|" ]; then progress="-"; fi;
if [ "$progress" == "\\" ]; then progress="|"; fi;
if [ "$progress" == "_" ]; then progress="\\"; fi;
if [ "$progress" == "/" ]; then progress="_"; fi;
if [ "$progress" == "-" ]; then progress="/"; fi;
fi
done
suffix='K'
if [ `echo "$total > 1024" | bc` = 1 ]; then
total=`echo "scale=2; $total / 1024" | bc`
suffix='M'
if [ `echo "$total > 1024" | bc` = 1 ]; then
total=`echo "scale=2; $total / 1024" | bc`
suffix='G'
fi
fi
echo
echo "Total size of installed packages is $total $suffix"And here's a version with a simpler and more informative progress meter:
#!/bin/bash
total=0
progress="1"
count=`pacman -Q | wc -l`
echo "Reading info of "$count" packages reported by 'pacman -Q'.
This may take few minutes..."
for pkg in `pacman -Q | sed 's/\ .*//'`
do
printf "\rprocessing file "$(( progress++ ))"..."
s=`pacman -Qi $pkg | sed -e '/Installed\ Size/!d; s/Installed\ Size\ :\ *//; s/\ K//; s/,/./'`
if [ "$s" != "" ]; then
total=`echo $total" + "$s | bc`
fi
done
suffix='K'
if [ `echo "$total > 1024" | bc` = 1 ]; then
total=`echo "scale=2; $total / 1024" | bc`
suffix='M'
if [ `echo "$total > 1024" | bc` = 1 ]; then
total=`echo "scale=2; $total / 1024" | bc`
suffix='G'
fi
fi
echo
echo "Total size of installed packages is $total $suffix"It works, good job. I didn't know about bc!
Oh, and welcome to the Arch BBS!
Last edited by peets (2007-12-30 18:49:22)
Offline
Yeah
this is good tune.
I'm really happy of that there is somebody who takes interest in it.
But I don't know how to speed up the script. Is slowness pacman or script cause? Maybe use of tupac can speed up script. On the other hand perhaps nobody run script quickly times over ![]()
And I'm sorry for my english, if it is horrible ![]()
Offline