Skip to content

Instantly share code, notes, and snippets.

@glarrain
Last active September 9, 2015 20:53

Revisions

  1. glarrain revised this gist Sep 9, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion get-ubuntu-installed-packages.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/bin/bash
    #pkginstalls.sh

    # source: https://help.ubuntu.com/community/ListInstalledPackagesByDate
    #creates text file with a list of all packages installed by date

    #first append all info from archived logs
  2. glarrain created this gist Sep 9, 2015.
    44 changes: 44 additions & 0 deletions get-ubuntu-installed-packages.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #!/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