56

Does anyone know if there's an easy way to find a list of packages installed, sorted by date, when using aptitude (or apt-get)?

I installed a bunch of packages to try something new, but it didn't work out. I'd like to remove all of these packages, to get back some disk space.

I've tried just looking at the list of .deb files downloaded, but that seems like a rather backwards way of doing it (although it did work).

Wings
  • 117
  • 2
  • 19
Mikeage
  • 663

8 Answers8

44

Unfortunately, dpkg (the package handler aptitude works on top of) does not specifically save the install date of packages, although there's thoughts of adding it. However, the install date can be found by looking at the date stamp of files written to the directory /var/lib/dpkg/info.

  • 4
    If you use this approach, be sure to only check the timestamps on the *.list files as the other files are stamped with the package date. – Dave Sep 13 '12 at 20:50
21

By default, aptitude writes to a log file /var/log/aptitude. It produces output like this:

===============================================================================

Aptitude 0.8.12: log report Sun, Oct 1 2021 23:59:59 +1300

IMPORTANT: this log only lists intended actions; actions which fail due to dpkg problems may not be completed.

Will install 6 packages, and remove 0 packages. 31.3 MB of disk space will be used ======================================== [UPGRADE] libc-dev-bin:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2 [UPGRADE] libc6:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2 [UPGRADE] libc6:i386 2.31-0ubuntu9 -> 2.31-0ubuntu9.2 [UPGRADE] libc6-dbg:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2 [UPGRADE] libc6-dev:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2 [UPGRADE] libc6-i386:amd64 2.31-0ubuntu9 -> 2.31-0ubuntu9.2 ========================================

Log complete.

This shows the exact date and packages that aptitude installed. To configure this (in /etc/apt/apt.conf or in a separate file in /etc/apt/apt.conf.d/), follow the Configuration file reference in aptitude manual (also available from "Help > User's Manual" in the menu):

Option:Aptitude::Log

Default:/var/log/aptitude

Description: If this is set to a nonempty string, aptitude will log the package installations, removals, and upgrades that it performs. If the value of Aptitude::Log begins with a pipe character (ie, ``|''), the remainder of its value is used as the name of a command into which the log will be piped: for instance, |mail -s 'Aptitude install run' root will cause the log to be emailed to root. To log to multiple files or commands, you may set this option to a list of log targets.

andrybak
  • 337
jeremiah
  • 400
  • 2
    Please post the link and how to implement it. Just referring to some manual text is not very helpful. – not2qubit Apr 26 '18 at 13:46
16

There is a simple way to see all packages installation date. Just execute:

grep " install" /var/log/dpkg.log*

As a result you will get a list of all installed packages with exact date and time.

Thanks for comments which lead me to that solution.

jmarceli
  • 406
  • 4
  • 8
  • 2
    The cd command is not necessary if you use the full path in the catcommand... – papukaija Jul 21 '13 at 00:15
  • 1
    The purpose of cd command was to ls inside this directory to check available dpkg.log files. But better solution will be running ls /var/log | grep 'dpkg.log' in order to list log files. Sorry for the mess. – jmarceli Jul 21 '13 at 01:27
  • 2
    or just "grep install /var/log/dpkg.log*" ? – Marc Van Daele Oct 25 '17 at 10:19
  • 1
    Huh, I didn't know cat | cat was a thing you could do. But why not cat both files in one command? (Or even better: just do what @MarcVanDaele says.) – mwfearnley Dec 18 '17 at 10:58
12

I found this one here on the web. It creates a history of dpkg out of the dpkg log file.

It looks very simple.

function apt-history(){
      case "$1" in
        install)
              cat /var/log/dpkg.log | grep 'install '
              ;;
        upgrade|remove)
              cat /var/log/dpkg.log | grep $1
              ;;
        rollback)
              cat /var/log/dpkg.log | grep upgrade | \
                  grep "$2" -A10000000 | \
                  grep "$3" -B10000000 | \
                  awk '{print $4"="$5}'
              ;;
        *)
              cat /var/log/dpkg.log
              ;;
      esac
}

Source

EDIT

I tried this script on Ubuntu 8.10 Server and it works very well. Could you provide some information, how you solved your problem?

guerda
  • 1,181
5
  • Use the dpkg logs

    locate dpkg.log | xargs cat {} | grep " install "
    
  • OR if you don't have locate

    find /var/log/ -name 'dpkg.log' | xargs cat {} | grep " install "
    
  • Use sort to ensure proper time based ordering

    locate dpkg.log | xargs cat {} | grep " install " | sort
    
  • Use tac (reverse cat)*, head e.g to get latest 4 entries

    locate dpkg.log | xargs cat {} | grep " install " | sort | tac | head -n4
    

e.g For the last command, I get:

2014-10-08 18:56:12 install xorg-server-source:all <none> 2:1.16.1-1
2014-10-08 18:49:34 install libelementary-data:all <none> 0.7.0.55225-1
2014-10-08 18:46:57 install e17:i386 <none> 0.17.6-1
2014-10-08 18:46:56 install libedje-bin:i386 <none> 1.8.6-2.1+b1
d a i s y
  • 5,511
a20
  • 159
  • 1
  • 5
  • 1
    Why would you use tac + head instead of tail? – Zanna Feb 16 '17 at 10:18
  • 1
    It's been a while, I've forgotten why - but it's possible there's an entirely good reason for it .. or maybe I had a blonde moment :D – a20 Feb 17 '17 at 09:25
3

You can also track down your previous actions by checking /var/log/apt/term.log, and older files term.log.1.gz etc.). It has timestamps and complete log from messages during install.

2

There is indeed an 'official' pkginstall.sh script that can do this. Follow the instructions in the official documentation. Briefly, download the script from the above link, make sure it is executable and then run with:

~/pkginstalls.sh

This will create pkginstalls.txt file in your home directory containing all the installed packages sorted by date.

BTW, this is the content of the script:

#!/bin/bash
#pkginstalls.sh
#creates text file with a list of all packages installed by date

#first append all info from archived logs

i=2
mycount=$(ls -l /var/log/dpkg.log.*.gz | wc -l)
nlogs=$(( $mycount + 1 ))

while [ $i -le $nlogs ]
do
if [ -e /var/log/dpkg.log.$i.gz ]; then
zcat /var/log/dpkg.log.$i.gz | grep "\ install\ " >> $HOME/pkgtmp.txt
fi
i=$(( $i+1 ))

done

#next append all info from unarchived logs

i=1
nulogs=$(ls -l /var/log/dpkg.log.* | wc -l)
nulogs=$(( $nulogs - $nlogs + 1 ))
while [ $i -le $nulogs ]
do
if [ -e /var/log/dpkg.log.$i ]; then
cat /var/log/dpkg.log.$i | grep "\ install\ " >> $HOME/pkgtmp.txt
fi
i=$(( $i+1 ))

done

#next append current log

cat /var/log/dpkg.log | grep "\ install\ " >> $HOME/pkgtmp.txt

#sort text file by date

sort -n $HOME/pkgtmp.txt > $HOME/pkginstalls.txt

rm $HOME/pkgtmp.txt

exit 0
Ron
  • 20,638
1

[ANSWERING THE ACTUAL QUESTION], Yes, there is an EASY way to look up packages installed on a particular date, even if it was done inside of terminal using apt-get.

If you install the Synaptic Package Manager, which is freely installable from the Ubuntu Software Center, you need only open its FILE menu and choose the "History" option. There you will find an accounting of all added and removed application packages, organized by date, regardless of how they came to be installed or removed.

bercik
  • 3
gyropyge
  • 2,558
  • 1
  • 16
  • 11