I am running a Linux instance on ec2, snap sorting of image is disabled.

While trying to un-install open-jdk from the system. I stupidly run the command

sudo apt-get remove open*

It started removing many packages, so I stopped the process by Ctrl+C.

I did it twice:

  • sudo apt-get remove open*
  • sudo apt-get remove openjdk*

I stopped the process (Ctrl+C) in between for both of them.

Now I see that my other application are not working, because of the packages removed.

Please advice, how can I go back to the state before apt-get remove.

Thanks in advance.

  • I'm sure that apt-get informed you which package were be going to be removed. – Braiam Apr 2 '14 at 21:27

If you look into the file /var/log/dpkg.log, you will see all operations regarding packages. So the list of removed packages can be retrieved from this log.

$ LIST=$(grep remove /var/log/dpkg.log|grep -v startup|grep open|awk '{print $4}')
$ sudo apt-get install $LIST

will build a list of package starting by open that were removed, put them in a shell variable and allow you to install them back in one shot.


You can get the information about recently removed packages(What are all the packages that are recently removed) in /var/log/dpkg.log file along with the date and time.

awk '$3=="remove"' /var/log/dpkg.log 

Find and reinstall the packages via apt-get.

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.