0

I have a directory full of RPM files recently installed (gotten by running yum install --downloadonly prior to the install).

I want to know remove all these RPMs to get close to a 'fresh' install for testing reasons.

Is there an easy way to uninstall all RPMs listed in the directory at once?

I tried this:

find . *.rpm | sed "s/.rpm$//g" | xargs sudo yum remove

but I get the message "no match for arguments ./" for each rpm in the list, so something is wrong with the command.

5
  • If you run just the first two commands in the pipeline, you will easily see what is wrong with the command. In fact, that's what you should always do: run the commands that produce the list that you want to operate on, before piping that into the command that actually does the operation. E.g. imagine you want to delete some files with find .... | munge | xargs rm: you want to make sure that the first part produces exactly what you expect or you'd be deleting files you want to keep. – NickD Jun 2 '17 at 20:16
  • BTW, the find should probably be find . -name '*.rpm' to restrict it to just files with .rpm suffix in this directory and all subdirs. If you don't have subdirs, then ls *.rpm in the place of find would suffice. – NickD Jun 2 '17 at 20:24
  • Hmmm....why not simply do a fresh install? It will probably be a lot easier after you account for all the dependencies and such. Sometimes removal of a package pulls in stuff that is still needed for removal. – mdpc Jun 2 '17 at 22:51
  • yum will rarely remove exactly the same set of packages and files that it installed unless you remove the packages in exactly the opposite order of installation. And even then there is no guarantee as libraries may have been upgraded to a later version, etc. – fpmurphy Jun 2 '17 at 23:52
  • @ndpc I'm doing testing of complex RPM I'm building. Doing a fresh install each time is tedious. I will do a complete reinstall later, when I'm closer to finished, to verify everything, until then I like having a quick script to allow me to get a 95% solution for sanity testing to detect most issues quickly – dsollen Jun 5 '17 at 14:17
1

One way:

rpms=( *.rpm )
sudo yum remove "${rpms[*]%.rpm}"
1

Another way to accomplish this mass removal:

for i in *.rpm
do 
    sudo yum remove $(basename "$i" | sed "s/.rpm$//g")
done

basename will strip all preceding path values, leaving only the filename after which the .rpm is stripped from the end.

Note:

Adding -y after the sudo yum remove will eliminate the need to manually enter 'y' when prompted for each file to be uninstalled.

1
  • This will do a yum remove for each file, rather than one for the whole set. It doesn't matter much for a one-off operation like this, but it's worth keeping in mind. – NickD Jun 3 '17 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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