[SOLVED] installation trimming helper (low space? which package to remove?)
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Great idea! I don't know if I would've thought of that, even though I sort by installed size on both Windows and my Android phone frequently. I just never thought to do it with Slackware. However, I would suggest changing the echo statement to only display when someone asks. I think I would end up finding it annoying to have it echoed every time.
Something like the following would allow for normal expectations from the commandline (obviously formatting it to your liking). It would take wg with either -h or --help and display the echo statement. Then if it detects anything else, it assumes it is the rest of the command and proceeds accordingly. You could also throw in a quick check for a second argument, and if it doesn't exist, you could display the help too.
Code:
#!/bin/sh
#
# (GPL) cest73@ya.ru
#
help()
{
echo "wg stands for Which Goes ?"
echo "list (20?) largesst installed packages"
echo "usage : "
echo -ne " wg [how many] [regep filter]\n\n"
}
doit()
{
N=${N:-20}
shift
G=${G:-.}
grep "UNCOMPRESSED " /var/log/packages/* \
| grep $G \
| sed -e s/"\/.*\/"/":"/g \
| awk -F: '{print $4 " / " $2}' \
| sort -b -h -r \
| head -n $N
}
case "$1" in
-h|--help)
help ;;
*)
N=$1
G=$2
doit ;;
esac
EDIT: Got home and once I tried it, I found it didn't pass the arguments through the case statement (not really sure why, but there's probably an easy way to fix it...), so instead I just set the N and G variables in the case statement itself.
One other suggestion after using it a bit... it might be nice to just specify the term and use the default number (20). That way, you could just type wg alien and have it spit out the top 20 alien packages instead of wg 20 alien. I would probably reverse the "[how many] [regep filter]" options... but that's just me.
If you feel I'm overstepping my bounds with these suggestions (and adding the case statement), please let me know. I'm sorry if that is the case. Feel free to let me know you're not interested in making any or all of my changes and I'll just modify a local copy
Last edited by bassmadrigal; 10-20-2016 at 04:34 PM.
This is basically what my darkstar-packsize does, but it actually computes the package size based on the files found on the system. Early incarnations of it was a shell script not unlike yours, but I found the UNCOMPRESSED SIZE was often misleadingly large, since I can't help myself to not remove "useless" files, such as locale, icons, gtk-docs, info-pages... I'm sorting the other way though, but that's nothing `tac` can't fix..
Great idea! I don't know if I would've thought of that, even though I sort by installed size on both Windows and my Android phone frequently. I just never thought to do it with Slackware. However, I would suggest changing the echo statement to only display when someone asks. I think I would end up finding it annoying to have it echoed every time.
Something like the following would allow for normal expectations from the commandline (obviously formatting it to your liking). It would take wg with either -h or --help and display the echo statement. Then if it detects anything else, it assumes it is the rest of the command and proceeds accordingly. You could also throw in a quick check for a second argument, and if it doesn't exist, you could display the help too.
Code:
#!/bin/sh
#
# (GPL) cest73@ya.ru
#
help()
{
echo "wg stands for Which Goes ?"
echo "list (20?) largesst installed packages"
echo "usage : "
echo -ne " wg [how many] [regep filter]\n\n"
}
doit()
{
N=${N:-20}
shift
G=${G:-.}
grep "UNCOMPRESSED " /var/log/packages/* \
| grep $G \
| sed -e s/"\/.*\/"/":"/g \
| awk -F: '{print $4 " / " $2}' \
| sort -b -h -r \
| head -n $N
}
case "$1" in
-h|--help)
help ;;
*)
N=$1
G=$2
doit ;;
esac
EDIT: Got home and once I tried it, I found it didn't pass the arguments through the case statement (not really sure why, but there's probably an easy way to fix it...), so instead I just set the N and G variables in the case statement itself.
One other suggestion after using it a bit... it might be nice to just specify the term and use the default number (20). That way, you could just type wg alien and have it spit out the top 20 alien packages instead of wg 20 alien. I would probably reverse the "[how many] [regep filter]" options... but that's just me.
If you feel I'm overstepping my bounds with these suggestions (and adding the case statement), please let me know. I'm sorry if that is the case. Feel free to let me know you're not interested in making any or all of my changes and I'll just modify a local copy
Dude it's GLP You are very welcome for the addition!
This is basically what my darkstar-packsize does, but it actually computes the package size based on the files found on the system. Early incarnations of it was a shell script not unlike yours, but I found the UNCOMPRESSED SIZE was often misleadingly large, since I can't help myself to not remove "useless" files, such as locale, icons, gtk-docs, info-pages... I'm sorting the other way though, but that's nothing `tac` can't fix..
[snip]
Kudos for the great package suite there
I knew wg was useful, but I didn't bother for any accuracy just mere comparison: wg is merely a tool for picking space hogs, nothing about accuracy:
Where I in for any accuracy, I would use 1k blocks and not -h switch and end up probably using Your tool?
#!/bin/sh
#
# (GPL) SCerovec & bassmadrigal on linuxquestions.org
#
#
# changelog:
#
# development started by bassmadrigal
# shift_bugfix and enhanced parameter evaluation by SCerovec
#
A=$1
B=$2
version()
{
echo "Version 0.2-alpha"
}
howto()
{
cat <<EOF
list (20?) largest installed packages
wg stands for Which Goes ?
parameters :
-h :get therse usage instructions
--help
-u
--usage
number :list this much packages, if omitted
defaults to 20
regexp :GNU regular expression evaluated by
grep to filer out packages of
interest
Parameters will be accepted in any order:
wg 12 SBo
wg alien 15 -both will work properly.
EOF
}
doit()
{
grep "UNCOMPRESSED " /var/log/packages/* \
| grep "${G}" \
| sed -e s/"\/.*\/"/":"/g \
| awk -F: '{print $4 " / " $2}' \
| sort -b -h -r \
| head -n $N
}
# empty parameters?
if [ "X${A}${B}" == "X" ];then
#defaults
N=20
G=.
else
# non numeric vars evaluate to 0
# and upon increment are equal to 1
# as well as any number less than 1
if (( +A > 1 )) ; then
# 1st is numeric
N=${A:-20}
G=${B:-.}
elif (( +B > 1 )) ; then
# 2nd is numeric
G=${A:-.}
N=${B:-20}
else
#none gnumeric O.o ?
N=20
G="${@}"
fi
fi
case "$1" in
-h|--help|-u|--usage)
howto ;;
-v|--version)
version ;;
*)
doit ;;
esac
changelog:
too many to count (just kidding)
parameter handling
expanded online help (wg -h)
improved stability
user friendlyness a notch up
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.