Erase multiple packages using rpm or yum

Using yum

List and remove the indicated packages and all their dependencies, but with a y/N confirmation:

yum remove 'php*'

To bypass the confirmation, replace yum with yum -y.

Using rpm

This section builds upon the answers by twalburg and Ricardo.

List which RPMs are installed:

rpm -qa 'php*'
rpm -qa | grep '^php'  # Alternative listing.

List which RPMs which will be erased, without actually erasing them:

rpm -e --test -vv $(rpm -qa 'php*') 2>&1 | grep '^D:     erase:'

On Amazon Linux, you may need to use grep '^D: ========== ---' instead.

If the relevant RPMs are not listed by the command above, investigate errors:

rpm -e --test -vv $(rpm -qa 'php*')

Erase these RPMs:

rpm -e $(rpm -qa 'php*')

Confirm the erasure:

rpm -qa 'php*'

The usual tool for this job is xargs:

rpm -qa | grep 'php' | xargs rpm -e

This will call rpm -e with all packages named in the standard input of xargs as arguments.

Tags:

Unix

Rpm

Yum