17

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?

  • Well, yes. What else would you expect? Do you want to show only those you ran from the terminal and not those that were run by a GUI or something? Please edit your question and clarify. – terdon Oct 1 '15 at 11:39
  • @terdon Okay made a new edit – TellMeWhy Oct 1 '15 at 11:44
  • 1
    There are logs of dpkg in /var/log/dpkg.log*. – Velkan Oct 1 '15 at 11:55
  • 1
    @ParanoidPanda That fails in various ways. History truncations, things run in other shells, things removed from history, or never put there in the first place, things installed from scripts, things run by other users etc etc – Squidly Oct 1 '15 at 13:27
  • 1
    @MrBones: I know, and I have stated so in my answer (and in the comments below it). However the OP asked for a way to view all the instances when they have manually executed the apt-get install command to install a package, and I have provided a solution which gives this information unless the history file has been altered in certain ways (e.g.: the entries have been removed). – user364819 Oct 1 '15 at 13:32
20

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.*'
  • I'll test this out when I get home and accept it if it works :) – TellMeWhy Oct 1 '15 at 14:01
  • It's not! check out the update: askubuntu.com/a/680405/320386 – kos Oct 1 '15 at 16:56
  • Use this, is way more safer for this task: zcat /var/log/apt/history.log.*.gz | cat - /var/log/apt/history.log | grep -Po '^Commandline:(?=.* install ) \K.*' | sed '1,4d': grep -Po '^Commandline:(?=.* install ) \K.*' will filter only the apt-get commands containing install with a leading and trailing space, sed '1,4d' might be dependant on the specific installation; in mine 1,4 deletes exactly the number of entries coming from Ubiquity, which are those you want to remove. Let me know if the number is the same on your installation, that way at least we have a baseline :| – kos Oct 1 '15 at 18:10
  • @kos I get extra lines such as apt-get -o APT::Status-Fd=4 -o APT::Keep-Fds::=5 -o APT::Keep-Fds::=6 -q -y --no-remove install linux-generic with the new command. Are they the Ubiquity lines? – Arronical Oct 2 '15 at 8:29
  • No, those look like they came from Software Updater; there's no way to distinguish from commands run from the user and commands run by some apt-get frontend, aside from Ubiquity which runs only once (for example aptdaemon entries will be showed by that command as well). The best bet though is still to use that command, which at least excludes the Ubiquity entries. – kos Oct 2 '15 at 12:09
9

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

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

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 -Po '^Commandline: apt-get install (?!.*--reinstall)\K.*'

becomes

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

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.
2

Here is script which prints only the currently installed top level packages, where "top level packages" is defined as atp packages upon which no other atp packages depend. If such top level programs were installed by atp 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-chache
  • 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 not. Mentioned just to bring awareness to the fact.
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.

  • 1
    Will I get all the history with this? – TellMeWhy Oct 1 '15 at 13:10
  • @DevRobot: Unless you have manually altered the entries with the apt-get install in them in the .bash_history file, or deleted this file, the command will show you all the instances when you have executed a command with the string apt-get install within it on your user account (even if you run the command as root and therefore not exactly as your user account - that is running a command with sudo). – user364819 Oct 1 '15 at 13:26
  • 2
    It might have a problem if you've entered more than 200 commands though – Arronical Oct 1 '15 at 13:51
  • 2
    @Arronical proof is expected when making claims ;-) – Rinzwind Oct 1 '15 at 14:03
  • 1
    I myself would assume 500 to be the default ( gnu.org/software/bash/manual/html_node/… ). – Rinzwind Oct 1 '15 at 14:10
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

  • apt-mark showmanual shows all packages installed when the OS was installed too, rather than just those actually manually installed. It's an odd way for it to behave! – Arronical Oct 1 '15 at 12:42
  • 1
    This doesn't necessarily give specific details as to the history. What people need to look at is /var/log/apt/history.log and similar files. You only get the list of manually selected and autoselected packages. You don't give any chronological history of what was installed, what was removed, what was upgraded, etc. from this answer. – Thomas Ward Oct 1 '15 at 12:54
  • @Arronical - Where is the man page for apt -mark showmanual? I can't see it on the Ubuntu 16.04 LTS man page for apt: <manpages.ubuntu.com/manpages/xenial/en/man8/apt.8.html>. – Craig Hicks Aug 22 '17 at 5:44
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"'
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.*'

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.