13

I was using one Linux server with CentOS7 installed for testing and installing some tools. And now I don't remember how many packages I installed.

I want to remove all that packages so my server would be like new as it was. I don't want to search for every package and remove one by one. Is there any way to remove them with just only one command?

3
  • /var/log/yum.log might be helpful, it lists both the package name and a timestamp. As far as I can see, it doesn't list packages added by the initial installs. – Ulrich Schwarz May 11 '16 at 7:48
  • The yum.log file would list all packages I installed, but how could i delete all of them with only 1 command? – The One May 11 '16 at 8:06
  • 2
    "Standard shell techniques" ;) like sudo yum remove $(gawk '$0 ~ /Installed/ {printf "%s ", $NF}' /var/log/yum.log) – Ulrich Schwarz May 11 '16 at 8:18
15

List all the files in the reverse order of their installation date into a file:

rpm -qa --last >list

You'll get lines like

atop-2.1-1.fc22.x86_64                        Wed Apr 13 07:35:27 2016
telnet-server-0.17-60.fc22.x86_64             Mon Apr 11 20:10:43 2016
mhddfs-0.1.39-3.fc22.x86_64                   Sat Apr  9 21:26:06 2016
libpcap-devel-1.7.3-1.fc22.x86_64             Fri Apr  8 09:40:43 2016

Choose the cutoff date that applies to you and delete all the lines that follow it. Give the remaining lines to yum to remove, after removing the date part. Eg

sudo yum remove $(awk '{print $1}' <list)
0
7

You can also try with yum history and usually you get a numbered list of what has been installed, like :

[root@localhost ~]# yum history
Loaded plugins: product-id, refresh-packagekit, subscription-manager
Updating Red Hat repositories.
ID | Login user               | Date and time    | Action(s)      | Altered
 3 | root <root>              | 2011-09-14 14:36 | Install        |    1   
 2 | root <root>              | 2011-09-12 15:48 | I, U           |   80   
 1 | System <unset>           | 2011-09-12 14:57 | Install        | 1025  

and you can use afterwards yum history undo 3 for example.

More details about yum history here.

0
0

In order to rollback every history transactions, you could use the o-liner below:

# yum history list|awk '$1 ~ /[0-9]+/ {print $1}'| while read a; do yum history undo -y $a; done

Be cautious while running this command, because it will remove all your installed packages! If you want confirmation, you can remove the -y flag.

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.