Tuesday, October 4, 2022

[SOLVED] remove multiple rpm packages using one bash command

Issue

I'd like to use a single bash command to uninstall several packages.

# rpm -qa | grep php

php-common-5.4.16-45.el7.x86_64
php-5.4.16-45.el7.x86_64
php-mysql-5.4.16-45.el7.x86_64
php-pdo-5.4.16-45.el7.x86_64
php-cli-5.4.16-45.el7.x86_64

will give me an output of all the pakcages I'd like to remove, however, how can I pipe that into a remove package command? Something like this:

# rpm -qa | grep php | yum remove ${package}

Solution

I tried this and it worked.

rpm -qa | grep php | while read -r line; do yum remove -y $line; done


Answered By - raw-bin hood
Answer Checked By - Willingham (WPSolving Volunteer)