Skip to content

Instantly share code, notes, and snippets.

@knez
Created August 19, 2019 12:19
Show Gist options
  • Select an option

  • Save knez/396a0d51ae353efa4d4c3f27bc91616e to your computer and use it in GitHub Desktop.

Select an option

Save knez/396a0d51ae353efa4d4c3f27bc91616e to your computer and use it in GitHub Desktop.
List all user-installed packages (Debian/Ubuntu)
#!/bin/bash
# Lists all user-installed packages
logfile="/var/log/apt/history.log"
logs="zcat $logfile.*.gz | cat - $logfile"
regex="^Commandline: (apt|apt-get) +install +\K( *(\w+-?)+)+"
packages=$(eval $logs | grep -oP "$regex" | tr -s ' ' '\n' | sort -u)
for pkg in $packages;
do
# check if a package is installed
grep-status -PX $pkg &>/dev/null
if [[ $? -eq 0 ]]; then
echo $pkg
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment