Tip: Extract RPM name without version numbers

April 11, 2012 at 05:56 PM | categories: Tips, Linux | View Comments
for rpm in $(rpm -qa|sort); do
    rpm=${rpm##*/};
    rpm=${rpm%%-[0-9]*};
    echo ${rpm};
done

You can also use a simpler command just from within rpm

rpm -qa --queryformat "%{NAME}\n"|sort

The first option comes in handy when you have files in a directory for example

for rpm in $(find /mnt/rpms -type f -name *.rpm|sort); do
    rpm=${rpm##*/};
    rpm=${rpm%%-[0-9]*};
    echo ${rpm};
done

blog comments powered by Disqus