How to list automatically or "manually" installed packages

Aptitude (an APT front-end) has long been able to distinguish between packages as being automatically installed (based on some dependancy that another package required) or "manually" installed. Since Debian Lenny (5.0) this capability is integrated into the APT package management system and most probably Aptitude's functionality got a lot thinner (since it doesn't have to implement something that's already in APT's core).
I could not find a method to do this (ie. list the manual/auto installed status of packages) the APT-way, but Aptitude's search function does it well enough.
Here's the command to list automatically installed packages:
aptitude search '.*' | grep '^i.A' | less
And the trivial opposite (list of manually installed packages):
aptitude search '.*' | grep '^i.[^A]' | less

In more recent APT versions apt-cache has a showauto parameter which lists automatically installed packages. Doing the reverse (listing manually installed packages) is quite simple too:
autopkgs="$(apt-cache showauto)"
for pkg in $(dpkg --get-selections | awk '/[^a-z](install|hold)$/{print $1}'); do echo "$autopkgs" | grep "^${pkg}\$" > /dev/null 2>&1 || echo "$pkg"; done

The latter comes handy if you don't have aptitude installed.

Syndicate content