Last active
April 9, 2024 05:08
-
-
Save Ozymandias42/fa403fe0eb5576ffc9151427d16e8126 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Single Liner | |
while [[ $(zypper pa --unneeded|tail -n+5|wc -l) -gt 0 ]]; do zypper pa --unneeded |tail -n+5|cut -d'|' -f3 | xargs sudo zypper rm; done | |
#Bash functions | |
zypper-cleanup() { | |
thingsToClean=$(zypper pa --unneeded|tail -n+5|awk -F'|' '{print $3}') | |
if [[ ${#thingsToClean[@]} -ne 0 ]]; then | |
echo ${thingsToClean[@]}|xargs sudo zypper rm -u | |
else | |
echo "Nothing to cleanup" | |
fi | |
} | |
#Alternatively | |
zypper-autoremove() { | |
packages=($(zypper pa --unneeded --orphaned --installed-only|tail -n +5|awk '{print $5}')) | |
length=${#packages[@]} | |
if [ $length -ge 0 ]; then | |
cat <<-EOF | |
The following packages will be removed: | |
${packages[@]}^ | |
EOF | |
read -p 'Proceed [y|n]: ' answer | |
if [ "$answer" == "y" ]; then | |
echo ${packages[@]} | xargs -I% -n $length sudo zypper rm -u % | |
fi | |
else | |
echo "No orphaned or unneeded packages to remove" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment