This is similiar to this question: remove the low version number of file
Unfortunately the solution to the above question does not work for me, example:
Files (ls -vr *.pkg.tar.xz
):
wire-desktop-bin-2.11.2700-1-x86_64.pkg.tar.xz
wire-desktop-bin-2.11.2698-1-x86_64.pkg.tar.xz
wire-desktop-bin-2.11.2697-1-x86_64.pkg.tar.xz
webstorm-2016.3.3-1-x86_64.pkg.tar.xz
webstorm-2016.3.2-1-x86_64.pkg.tar.xz
visual-studio-code-1.9.0-1-x86_64.pkg.tar.xz
visual-studio-code-1.8.1-3-x86_64.pkg.tar.xz
pycharm-professional-2016.3.2-1-any.pkg.tar.xz
plasma5-applets-thermal-monitor-git-r63.fd41970-1-any.pkg.tar.xz
masterpdfeditor-qt5-3.7.10-2-x86_64.pkg.tar.xz
masterpdfeditor-4.0.30-1-x86_64.pkg.tar.xz
keepass-plugin-keeagent-0.8.1-3-any.pkg.tar.xz
jre-8u121-1-x86_64.pkg.tar.xz
jdk-8u121-1-x86_64.pkg.tar.xz
jabref-3.8.1-1-any.pkg.tar.xz
intellij-jdk-8u112b719-1-x86_64.pkg.tar.xz
intellij-jdk-8u112b657-1-x86_64.pkg.tar.xz
intellij-idea-ultimate-edition-2016.3.4-1-any.pkg.tar.xz
intellij-idea-ultimate-edition-2016.3.3-1-any.pkg.tar.xz
hstr-git-1.21.r10.gc0d3236-1-x86_64.pkg.tar.xz
google-chrome-56.0.2924.87-1-x86_64.pkg.tar.xz
google-chrome-56.0.2924.76-1-x86_64.pkg.tar.xz
gitinspector-0.4.4-1-any.pkg.tar.xz
dropbox-17.4.33-1-x86_64.pkg.tar.xz
chromium-widevine-1:1.4.8.962-1-x86_64.pkg.tar.xz
Now I need to find (and later remove) all old packages (version number != highest).
Using the solution from the other question:
ls -vr *.depot | awk -F- '$1 == name{system ("rm \""$0"\"")}{name=$1}'
produces this wrong result:
:: os/x86_64 » ls -vr *.pkg.tar.xz | awk -F- '$1 == name{system ("echo \""$0"\"")}{name=$1}'
wire-desktop-bin-2.11.2698-1-x86_64.pkg.tar.xz
wire-desktop-bin-2.11.2697-1-x86_64.pkg.tar.xz
webstorm-2016.3.2-1-x86_64.pkg.tar.xz
visual-studio-code-1.8.1-3-x86_64.pkg.tar.xz
masterpdfeditor-4.0.30-1-x86_64.pkg.tar.xz
intellij-jdk-8u112b657-1-x86_64.pkg.tar.xz
intellij-idea-ultimate-edition-2016.3.4-1-any.pkg.tar.xz <-----------
intellij-idea-ultimate-edition-2016.3.3-1-any.pkg.tar.xz <-----------
google-chrome-56.0.2924.76-1-x86_64.pkg.tar.xz
Notice this lists both idea-ultimate-edition
packages because of intellij-jdk
(awk splits at first -
). I don't really know how to solve this problem consistently.
These are Archlinux packages, even if pacman (Archlinux package manger) could help me here, I am building and storing them on a Debian system, so I would prefer a pure bash/awk/etc. solution.
awk
that mostly works for your list above isname = $0; sub("-[0-9].*", "", name)
, i.e. look for the first dash followed by a digit. This fails forplasma5-applets-thermal-monitor-git-r63.fd41970-1-any.pkg.tar.xz
though. It would be a lot safer if you could convince your package manager to give you the names and versions separately.