Linux: show apt history

At the moment the Linux distribution that I'm using is Debian, the packages manager that I'm usually to use in it is the apt and the simplest way to check apt-history is to use the bash script apt-history.

With apt-history we can check the list of packages installed, removed or upgraded with apt. As we can see the last update of the script has been wrote the 26/02/2005 but it is correctly working even now.

Unfortunately the site of its author seem abandoned and therefore I'm reporting it for backup purposes.

apt-history function:

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
}

This function has to be added in:

/root/.bashrc

To use the command apt-history we have to be superuser.

The possible commands are:

  • apt-history
  • apt-history install
  • apt-history remove
  • apt-history upgrade
  • apt-history rollback

This is a great way to check the install history on linux.