Skip to content

Instantly share code, notes, and snippets.

@glarrain
Last active September 9, 2015 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glarrain/e1e71fc8aa9139b7afe0 to your computer and use it in GitHub Desktop.
Save glarrain/e1e71fc8aa9139b7afe0 to your computer and use it in GitHub Desktop.
Write list of manually installed packaged (and when) in a Ubuntu system by looking in dpkg logs
#!/bin/bash
# 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
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
@glarrain
Copy link
Author

glarrain commented Sep 9, 2015

To just obtain a list of the packages installed at the moment (even those included by default in the OS) run

sudo dpkg -l > ~/dpkg-list.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment