How to list manually installed (added) packages in Ubuntu

ubuntu linux bash apt shell

Sometimes it might be very handy to list all packages that were manually installed with apt, so these could be installed on other machine, or just to see what was installed in the past manually. This means without dependencies, which should be resolved by apt and without packages that came with initial distro installation. This means that the lists contains only packages installed after initial setup.

I can't recall from where I've found following snippet, but it does the job done:

  comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)

Please note that sometimes initial-status.gz is not present in the system, currently there is no solution for this issue