Skip to main content
correction in the script
Source Link
The Quark
  • 454
  • 3
  • 14

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 for loop goes through each history.log or history.log.<n>.gz files 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 zipped

  • egrep -A 1 "Requested-By: ${USER}" filters entries in each history.log* file that have been requested by the user, the -A 1 option allows to output the line just after the Requested-By: ... line in the file, which is the line where the packages are listed

  • egrep "Install:" filters the requests for installing (vs for upgrading); to list both, replace by egrep "Install:|Upgrade:"

  • egrep -o "[[:alnum:]:~+.-]+ \([[:alnum:]:~+\.\ ,-]+)\$" filters entries in the list of packages of the form package-name (version, [version, ...], [automatic]) returning just the match (-o option); packages marked automatic are packages installed automatically to fulfill dependency

  • egrep -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.

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 for loop goes through each history.log or history.log.<n>.gz files 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 zipped

  • egrep -A 1 "Requested-By: ${USER}" filters entries in each history.log* file that have been requested by the user, the -A 1 option allows to output the line just after the Requested-By: ... line in the file, which is the line where the packages are listed

  • egrep "Install:" filters the requests for installing (vs for upgrading); to list both, replace by egrep "Install:|Upgrade:"

  • egrep -o "[[:alnum:]:~+.-]+ \([[:alnum:]:~+\.\ ,-]+)\$" filters entries in the list of packages of the form package-name (version, [version, ...], [automatic]) returning just the match (-o option); packages marked automatic are packages installed automatically to fulfill dependency

  • egrep -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.

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 for loop goes through each history.log or history.log.<n>.gz files 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 zipped

  • egrep -A 1 "Requested-By: ${USER}" filters entries in each history.log* file that have been requested by the user, the -A 1 option allows to output the line just after the Requested-By: ... line in the file, which is the line where the packages are listed

  • egrep "Install:" filters the requests for installing (vs for upgrading); to list both, replace by egrep "Install:|Upgrade:"

  • egrep -o "[[:alnum:]:~+.-]+ \([[:alnum:]:~+\.\ ,-]+)\$" filters entries in the list of packages of the form package-name (version, [version, ...], [automatic]) returning just the match (-o option); packages marked automatic are packages installed automatically to fulfill dependency

  • egrep -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.

Source Link
The Quark
  • 454
  • 3
  • 14

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 for loop goes through each history.log or history.log.<n>.gz files 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 zipped

  • egrep -A 1 "Requested-By: ${USER}" filters entries in each history.log* file that have been requested by the user, the -A 1 option allows to output the line just after the Requested-By: ... line in the file, which is the line where the packages are listed

  • egrep "Install:" filters the requests for installing (vs for upgrading); to list both, replace by egrep "Install:|Upgrade:"

  • egrep -o "[[:alnum:]:~+.-]+ \([[:alnum:]:~+\.\ ,-]+)\$" filters entries in the list of packages of the form package-name (version, [version, ...], [automatic]) returning just the match (-o option); packages marked automatic are packages installed automatically to fulfill dependency

  • egrep -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.