My Package Remover
It all started with me wanting to clean up a system with zillion packages .
After an half ass attempt to find out what are the packages with biggest size,vedanta pointed me to the rpm's --queryformat option.
So this solved part of the job,finding out what packages to remove.
So here it is .
$rpm --queryformat="%{size} %{name}\n" -qa |sort -n
After this obviously when you want to remove a package ,it takes time as the package maybe required by other packages.So i thought of writing a small bash script to do it.So here goes
So thats it just run it with the a package name as an argument and toast your system.
By and by got to know that if you use a pipeline in the while loop above fullpackage scope wont last after the while loop.Bash will put the value it has before it entered the loop thats because while is done using a subshell.
But how does it matter if its a pipe or a redirection??......
After an half ass attempt to find out what are the packages with biggest size,vedanta pointed me to the rpm's --queryformat option.
So this solved part of the job,finding out what packages to remove.
So here it is .
$rpm --queryformat="%{size} %{name}\n" -qa |sort -n
After this obviously when you want to remove a package ,it takes time as the package maybe required by other packages.So i thought of writing a small bash script to do it.So here goes
#!/bin/sh
removepackage()
{
local fullpackage=$*
if rpm -e $fullpackage 2>/dev/null
then
echo "Removed the damn package"
exit
else
rpm -e $* 2>&1 | awk -F")" '{print $2}' > /tmp/removepackages
while read package
do
fullpackage="$fullpackage $package"
done < /tmp/removepackages
fi
echo $fullpackage
removepackage $fullpackage
}
removepackage $*
So thats it just run it with the a package name as an argument and toast your system.
By and by got to know that if you use a pipeline in the while loop above fullpackage scope wont last after the while loop.Bash will put the value it has before it entered the loop thats because while is done using a subshell.
But how does it matter if its a pipe or a redirection??......
0 Comments:
Post a Comment
<< Home