Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to upgrade php from 5.3 to 5.4. I've installed it with rpm. I want clean install: delete all 5.3 packages, and install all necessary 5.4. Here is the command to see all installed packages:

rpm -qa |grep php

It prints out a list of packages, and I want to remove all them with:

rpm -e *pakage.name*

Can I iterate over all matches in grep results and use each match in:

rpm -e *grep.match*
share|improve this question
1  
rpm -qa does not need grep to be invoked. It accepts globbing as in rpm qa *php*. Also use yum instead as it will remove / reinstall necessary libraries –  val0x00ff Apr 14 at 19:39

4 Answers 4

up vote 5 down vote accepted

Try this:

rpm -qa | grep php | xargs rpm -e
share|improve this answer
    
Cool! Thanks =) –  Anatoliy Gusarov Apr 14 at 19:43

Try this script:

for p in $(rpm -qa |grep php) ; do rpm -e ${p} ; done
share|improve this answer
    
@terdon Thanks for the hint, I should really get used replacing those backticks with the $() notation ... –  phlogratos Apr 14 at 19:44
( IFS='
' ; printf 'rpm -e "%s"\n' $(rpm -qa |grep php) |
    . /dev/stdin )

There you go.

share|improve this answer

You generally don't want to remove packages like this in pieces since there's typically dependencies that you're skipping over. Better to do this removal all at once like so:

$ rpm -e $(rpm -aq | grep php)

Better still I would encourage you to use yum to do this vs. RPM.

$ yum remove $(rpm -aq | grep php)

Even better then these would be to figure out a pattern that matches all the PHP packages and tell YUM to remove based on the pattern . Yes YUM is aware of regular expressions.

$ yum remove 'php*'

You'll need to make sure that your entire list of packages will fit on the command line but doing this using xargs or individually is wrought with problems, if you tell rpm to remove 1/2 of the PHP related packages in one command, followed by another rpm command with the rest.

share|improve this answer
    
Thaks for explanation! Will try your advice next time. I've alredy removed all and have php5.4 installed. –  Anatoliy Gusarov Apr 14 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.