3

Here is the situation: say, at 17:00, I installed a lot of packages, I can see them in the ubuntu software center history. Also I can see them in the dpkg log file using the method provided by this thread. My question is: how can I delete them easily. There are so many, I can't delete them one by one in synaptic.

The thread I linded may have explain the method. However, I can't see the time specified in the command, for I don't want delete any other packages installed at other time.

3 Answers 3

3

Try this command,

awk '$1~/yyyy-mm-dd/ && $2~/hh:mm:ss/ && $3~/install/ { print $4}' /var/log/dpkg.log | xargs -I{} sudo apt-get -y remove {}

Example:

awk '$1~/2014-04-17/ && $2~/15:55:03/ && $3~/install/ { print $4}' /var/log/dpkg.log | xargs -I{} sudo apt-get -y remove {}

The above command will remove all the packages which are installed on 2014-04-17 at the time 15:55:03.

1
  • Thanks very much, your code is just what I want. I don't know exactly the meaning of your code. However I've split it to $p=(awk '$1~/2014-04-17/ && $2~/15:55/ && $3~/install/ { print $4}' /var/log/dpkg.log) and echo $p to check that the list is just the packages I installed. Then I do sudo apt-get remove $p to remove them. It works so great, thank! Apr 17, 2014 at 11:04
2

/var/log/dpkg.log lists all install commands with time stamps, just do a grep. Also, /var/log/apt/history.log lists all apt-get activity, including packages installed or removed in one go.

2
  • I still don't know how, could you explain more specific? how can I grep out all the package names, however without time stamps and other useless information such as status? Apr 17, 2014 at 10:26
  • I'm sure you will know the name of at least one package that got installed, let's say package xyz. Doing grep xyz /var/log/apt/history.log will give you a line starting with Install that lists all packages that were installed at that time, with version numbers. Copy that line to a text editor, strip out the version numbers and commas, leaving all the packages names on a single line. Now, in a terminal, enter sudo apt-get remove and paste that line after it. That should remove all packages that were unintentionally installed at that time.
    – Jos
    Apr 17, 2014 at 10:34
0

If you installed that through apt, you can use /var/log/apt/history.log. It's structure is as such:

Start Date: YYYY-MM-DD HH:MM:SS
Commandline: apt-get install package1 package2 package3 . . .
Install: library1 libary2 package1 package2
End-Date: YYYY-MM-DD HH:MM:SS

Knowing that we can use awk to search for particular date and time, descend one line bellow that, get rid of apt-get install line, leaving only the list of packages. For instance, here's a sample command:

awk -F':' '/2015-06-05 16:02:43/ {getline; gsub("apt-get install",""); print $2}' /var/log/apt/history.log

You can add pipe to xargs apt-get remove to remove those packages.

awk -F':' '/2015-06-05 16:02:43/ {getline; gsub("apt-get install",""); print $2}' /var/log/apt/history.log | xargs apt-get remove

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .