31

How can I view the history of apt-get install commands that I have manually executed?

It seems to me that all methods available show everything that has been installed right from the start of the Ubuntu installation.

How can I view the history of apt-get install since the time my system-installation process had completed?

TellMeWhy
  • 17,964
  • 41
  • 100
  • 142

8 Answers8

27

I think the answer given here by kos is the best way I've seen so far. Though as Software Center uses apt, anything that it has installed would be listed too.

The command is:

zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep -Po '^Commandline: apt-get install (?!.*--reinstall)\K.*'
Arronical
  • 20,241
13

Just type following command in your terminal to view all install logs.

grep " install " /var/log/dpkg.log
sigjuice
  • 103
7

To simplify @Arronical answer, A neat trick I learned recently is you can use zcat -qf to cat both txt and txt gzipped files.

zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep " install "

becomes

zcat -qf /var/log/apt/history.log* | grep " install "

From man zcat:

   -q --quiet
          Suppress all warnings.
   -f --force
          Force  compression  or  decompression  even if the file has multiple links or the corre‐
          sponding file already exists, or if the compressed data is read from  or  written  to  a
          terminal.  If  the  input  data is not in a format recognized by gzip, and if the option
          --stdout is also given, copy the input data without change to the standard  output:  let
          zcat  behave  as  cat.  If -f is not given, and when not running in the background, gzip
          prompts to verify whether an existing file should be overwritten.
jjcf89
  • 173
4

Here is script which prints only the currently installed top level packages, where "top level packages" are defined as apt packages upon which no other apt packages depend. If such top level programs were installed by apt or a package manager such as Synaptic, then they were manually chosen by the user.

#!/bin/sh
NumDaysAgo=18
find /var/lib/dpkg/info -name "*.list" -mtime -$NumDaysAgo \
    -exec stat -c $'%y\t%n' {} \; | \
sed -e 's,/var/lib/dpkg/info/,,' -e 's,\.list,,' | \
sort -r | \
while read Date Time Xxx Pkg
do 
    lncnt=$(apt-cache --installed rdepends $Pkg | wc -l)
    if [ $lncnt -eq "2" ]
        then echo "$Date $Time $Pkg"
    fi
done
echo "JOB COMPLETED: $BASH_SOURCE"

The packages are printed in reverse order under the assumption that the user is more likely to want the newer info sooner, and because the program is slow.

Program flow:

  • The program first gathers into a list all the installed packages by reading the filenames under /var/lib/dpkg/info/. The file mod times are the installation times.
  • That list is sorted in reverse order.
  • For each installed package $Pkg, a call to apt-cache rdepends $Pkg requests the reverse-dependencies of $Pkg. If there are no dependencies, then it is a top level package and the package info is printed: date time packagename

Notes:

  • The script depends upon the output format of apt-cache rdepends $Pkg which was intended for human eyes and could change in the future versions of apt.
  • The code for the part gathering filenames under /var/lib/dpkg/info/ came from this unix.stackexchange post. As that poster 'mikel' pointed out, the dpgk history logfiles are not reliable because they will be rotated out after reaching a certain volume.
  • Man page for apt-cache
  • The call apt-cache rdepends ... is very slow presumably because each call is computed by iterating through all the dependencies. Hence the above script starts from the newest installs to offer the user as much instant gratification as possible.
  • The --installed flag after apt-cache checks that the dpkg-installed packages are also apt-installed. If the user or another install software bypassed apt and used dpkg directly, it would be possible. THIS CASE HAS NOT BEEN TESTED, but I think something noticeable would be printed in either the standard or error output
  • The output does not include manually chosen packages which later became depended upon by a higher package. The output can also include packages which were installed via apt by other third party install software, and hence are not truly manually installed. However, if the purpose of the output is as a basis for setting up a restored Linux from a backup /home directory which included said third party software, then this output would be suitable.
  • Some of the package names include version numbers, and some do not. Mentioned just to bring awareness to the fact.
Thomas Ward
  • 78,878
1

If you want history of apt-get install commands use the following command:

grep "apt-get install" .bash_history

Output:

ravan@ravan:~$ grep "apt-get install" .bash_history

sudo apt-get install --no-install-recommends ubuntu-mate-core ubuntu-mate-desktop
sudo apt-get install xfce4
sudo apt-get install xfce4.12
sudo apt-get install pgadmin
sudo apt-get install touchegg
sudo apt-get install aptitude
sudo apt-get install aptitude
sudo gedit .bash_history | grep "apt-get install" 
sudo apt-get installvim
grep "apt-get install" .bash_history
cat .bash_history | grep "apt-get install" 

For other information referExtra information.

There is also more detailed installation information in /var/log/apt/ in the history.log and history.log.X.gz files and term.log and term.log.X.gz files

If you want history of only apt-get included commands, then

history | grep apt-get

Ravan
  • 9,567
1

If you want see all of the things you have installed by running:

sudo apt-get install [package]

And you have not messed with the bash history, nor are you wanting to view the history of this sort of installation type for another user (or all users) then you can just run:

history | grep "apt-get install"

And that should get you mostly relevant results.

0

Note that some arguments can be set before the install one, like the virtualmin script is doing during install: apt-get -y install packagename.

So if you want capture all install commands, you need to change the regex query.

zcat -qf /var/log/apt/history.log* | grep -Po '^Commandline: apt-get.*install (?!.*--reinstall)\K.*'
0

In order to see what You've installed and removed, reinstalled, etc. More info about the journey of apt-get installs.

The answer can be modified into an alias:

alias apted='zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | fgrep Commandline: | cut -d " " -f 2- | grep -P "^|install"'
userDepth
  • 2,040
Mike
  • 101