The following single-line command (in bash) worked for me:
for i in /var/log/apt/history.log*; do \
{ zcat $i 2>/dev/null || cat $i; } | \
egrep -A 1 "Requested-By: ${USER}" | \
egrep "Install:" | \
egrep -o "[[:alnum:]:~+.-]+ \([[:alnum:]:~+\.\ ,-]+)\$"" | \
egrep -v "automatic)"; done
It lists packages installed manually, whether they have been installed through the command line or through Synaptic for example (in my case I have a mix of the both).
Explanation:
The
forloop goes through eachhistory.logorhistory.log.<n>.gzfiles in/var/log/apt/{ zcat $i 2>/dev/null || cat $i; }unzips and outputs the content of the file or just outputs the content of the file if it is not zippedegrep -A 1 "Requested-By: ${USER}"filters entries in eachhistory.log*file that have been requested by the user, the-A 1option allows to output the line just after theRequested-By: ...line in the file, which is the line where the packages are listedegrep "Install:"filters the requests for installing (vs for upgrading); to list both, replace byegrep "Install:|Upgrade:"egrep -o "[[:alnum:]:~+.-]+ \([[:alnum:]:~+\.\ ,-]+)\$"filters entries in the list of packages of the formpackage-name (version, [version, ...], [automatic])returning just the match (-ooption); packages markedautomaticare packages installed automatically to fulfill dependencyegrep -v "automatic)"filters out those packages that have been installed automatically
Feel free to comment if you see limitations or limit cases where this would not work, or a more straightforward way to extract that list.