You're lucky, apt-get
/ apt
writes a log at /var/log/apt/term.log
.
So you can find all your removed packages and reinstall them.
As you pressed Ctrl+Z, apt-get
is a stopped process in the brackground. So, frst of all, you should properly end apt-get
. Simply run fg
and wait until apt-get
is done (Yes that will finish removing the packages, but we will be able to get them back).
For others that might find this answer: If you pressed Ctrl+C instead, you might need to run sudo apt install -f
to fix unfinished removals etc.
Then, to get back your packages:
Find out the exact log time
# If it just happened:
apt_date=$(sudo grep 'Log started' /var/log/apt/term.log | tail -n1)
# or find manually ...
sudo less /var/log/apt/term.log
# ... and set the result as variable, we need in the next step.
apt_date="Log started: 2019-08-26 16:26:27"
Get all removed packages and reinstall them:
# Get all removed packages for this date and reinstall them:
sudo sed -n "/${apt_date}/,/Log ended/p" /var/log/apt/term.log \
| awk '/^Removing/{print $2}' \
| xargs -r sudo apt install
The following packages will be REMOVED:
". If you closed your terminal, good luck ;-) – pLumo Aug 26 '19 at 14:17apt
/apt-get
... – pLumo Aug 26 '19 at 14:20tor.
is recognized as a pattern, and thenapt
will treat it as such and find e.g.bla-storage-bla
which has nothing to do withtor
. – pLumo Aug 26 '19 at 14:40