Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to show the history of packages that were changed by apt-get via command line?

share|improve this question
possible duplicate of Is it possible to get a list of most recently installed packages? – BuZZ-dEE Aug 27 '15 at 15:59
up vote 84 down vote accepted

All actions with apt (apt-get) are logged. These files are available in /var/log/apt/. To view the most recent history log, execute:

less /var/log/apt/history.log

These logs gets rotated (every month I guess), old files will be suffixed with a number and compressed. So to view the next history log, use:

zless /var/log/apt/history.log.1.gz

To view the logs available:

ls -la /var/log/apt/
share|improve this answer
This is excellent. The only thing missing is who ran the commands. – Limited Atonement Apr 3 '12 at 17:33
@LimitedAtonement Have a look at /var/log/auth.log, it may contain the user running the installation. (this won't help if the installation was invoked through a shell/program running as root) – Lekensteyn Apr 3 '12 at 17:41
Also useful: zgrep, zcat – ishmael Sep 1 '15 at 23:33
does this file also log the dependency packages installed as a result of original apt-get? – Mahesha999 May 23 at 19:26
@Mahesha999 It does not, it only logs requested packages. Try /var/log/dpkg.log for the lower level installation details that included dependends. – Lekensteyn May 24 at 11:36

You can also make a short command to display the interesting content.

  • Add this custom function to your ~/.bashrc:

    ### pars for fun: install | remove | rollback
    function apt-history(){
          case "$1" in
                  grep 'install ' /var/log/dpkg.log
                  grep $1 /var/log/dpkg.log
                  grep upgrade /var/log/dpkg.log | \
                      grep "$2" -A10000000 | \
                      grep "$3" -B10000000 | \
                      awk '{print $4"="$5}'
                  cat /var/log/dpkg.log
  • And call it in a terminal like this:

    kreso@h17:~$ apt-history install
    2013-08-06 14:42:36 install gir1.2-nautilus-3.0:amd64 <none> 1:3.8.2-0ubuntu1~ubuntu13.04.1
    2013-08-06 14:42:36 install python-nautilus:amd64 <none> 1.1-3ubuntu1
    2013-08-06 14:42:37 install insync-nautilus:all <none> 1.0.20
    2013-08-07 14:41:37 install powertop:amd64 <none> 2.1-0ubuntu1
    2013-08-07 18:44:10 install libdiscid0:amd64 <none> 0.2.2-3build1
    2013-08-07 18:44:11 install sound-juicer:amd64 <none> 3.5.0-0ubuntu1

Taken from here

share|improve this answer

You can also use the following command to list recently installed packages

grep "\ install\ " /var/log/dpkg.log
share|improve this answer
even better: grep "\ install\ " /var/log/apt/history.log in case you need to copy and paste a list into apt-get – mchid Jul 27 '15 at 19:53

If you want those packages that were installed and not subsequently uninstalled, try this:

comm -23 <(grep "apt-get install" /var/log/apt/history.log | sed 's/.* //' | sort) \ 
<(grep "apt-get remove" /var/log/apt/history.log | sed 's/.* //' | sort) 

This is the installs minus any matching removes.


share|improve this answer
+1: Nice one-liner but only valid for the last log rotation period. Also instead of sort, use sort -uin both cases to avoid duplicate lines to show up such as in package like oracle-java8-installer and many others. – Cbhihe Jul 24 at 7:58

## Note: This will likely be slow the first run, because it is 
## grabbing ALL packages from var/log.
## If you save it to lspkgs.bsh
##  alias lspkgs='/fav/place/for/it/lspkgs.bsh'

declare PKG_LOG=/tmp/__tmp_pkgs_install_log__
declare UNSORTED_PKG_LOG=/tmp/__tmp_pkgs_install_log_unsorted__
declare PKG_LOG_TIMESTAMP=/tmp/__pkgs_install_log_timestamp__
declare ZENITY_HEIGHT=600 
declare ZENITY_WIDTH=500 

function rebuild_pkg_list() { 
date > "${PKG_LOG_TIMESTAMP}" 
rm -f "${PKG_LOG}" "${UNSORTED_PKG_LOG}" 
cat $(ls -1 /var/log/dpkg* | grep -v "gz\$")       >> "${PKG_LOG}" 
cat $(ls -1 /var/log/dpkg* | grep "gz\$") | gunzip >> "${PKG_LOG}" 
while IFS= read a; do 
 PKG=$(awk "/installed/{for(i=1;i<=NF;++i)if(\$i~/installed/){print \$(i+1);break}}" <<< "${a}")
 lastinstall=$(grep -n "status installed ${PKG}" "${PKG_LOG}" | tail -1 | grep -o '^[0-9]*[^0-9]' | sed 's/.$//')
 lastuninstall=$(grep -n "status not-installed ${PKG}" "${PKG_LOG}" | tail -1 | grep -o "^[0-9]*[^0-9]" | sed "s/.\$//")
 [[ -z "$lastuninstall" ]] || ((${lastuninstall}<${lastinstall})) && echo "${PKG}"
done < <(grep "\ installed\ " "${PKG_LOG}" | sort | uniq) | tee "${UNSORTED_PKG_LOG}" | zenity --height ${ZENITY_HEIGHT} --width ${ZENITY_WIDTH} --title "Compiling packages list, please wait..." --text-info
sort "${UNSORTED_PKG_LOG}" | uniq >  "${PKG_LOG}" 

function show_with_zenity() { 
 cat "${PKG_LOG}" | zenity --height ${ZENITY_HEIGHT} --width ${ZENITY_WIDTH} --title "Installed Packages (Upd:$(< "${PKG_LOG_TIMESTAMP}"))" --text-info

if (($#>0)); then 
 [[ "${1}" =~ -h ]] && echo "Usage: ${0##*/} <any flag other arg than -h to rebuild the packages list>" || rebuild_pkg_list
 [[ ! -f "${PKG_LOG}" ]] && rebuild_pkg_list
 ((${USE_ZENITY})) && show_with_zenity || cat "${PKG_LOG}"

exit 0
share|improve this answer
Unrelated to the script's purpose, I find it interesting that AU's format parser does NOT understand yr last if-conditional on $#. See how everything after the # sign is interpreted as a comment. But no matter, the bash syntax is perfectly correct. – Cbhihe Jul 24 at 7:44
Yea, I've seen pygmentize get tripped up from time to time with Bash syntax -- there's a lot of special cases, seems like a few have been overlooked. They will probably get fixed quicker if an email is sent to the appropriate bug report mailing list. – A.Danischewski Jul 24 at 8:14
Yup. It behaves when quoting as in "$#" though. Anyway I'm not sure about its implementation here and the version installed. In fact AU is not listed by as a project using pygments. So I will flag it so mods can report that appropriately. – Cbhihe Jul 24 at 8:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.