Skip to content

Instantly share code, notes, and snippets.

@anderseknert
Created February 18, 2013 23:04
Show Gist options
  • Save anderseknert/4981582 to your computer and use it in GitHub Desktop.
Save anderseknert/4981582 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
logdir="/var/log/"
installed=""
# Scan all dpkg logs for installed packages
for file in ${logdir}dpkg.log*; do
if [ ${file##*.} = "gz" ]; then
installed=$installed`gzip -dc $file | grep ' installed' | cut -d' ' -f5`
else
installed=$installed`cat $file | grep ' installed' | cut -d' ' -f5`
fi
done
# Get all packages installed at the time of OS installation
os_installed=`gzip -dc ${logdir}installer/initial-status.gz | grep 'Package: ' | cut -d' ' -f2`
# Get all automatically installed packages
auto_installed=`apt-mark showauto`
# Concatenate all the installed packages..
all_installed="${installed}${os_installed}${auto_installed}"
# ..and remove all duplicates, which leaves only user installed packages
echo "${all_installed}" | sort | uniq -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment