E.g. using Aptitude:
$ aptitude show gimp linux-headers-3.2.0-2-686-pae
Package: gimp
New: yes
State: installed
Automatically installed: no
<snip>
Package: linux-headers-3.2.0-2-686-pae
New: yes
State: installed
Automatically installed: yes
<snip>
This shows two example packages on my system. The "Automatically installed" field shows if it is manually installed or dragged in by a dependency.
This information is available to APT, as you suspect. Depending on which tool you like to use, it will be found in different places, but it will most likely be called "Automatically installed" with a "Yes/No" value.
Info on specific package that dragged in a particular package
You can use apt-rdepends
(available in main repositories) to list forwards or backwards dependencies for a package. Example:
$ apt-rdepends -rp --state-follow=Installed \
--state-show=Installed linux-headers-3.2.0-3-686-pae
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-headers-3.2.0-3-686-pae
Reverse Depends: linux-headers-686-pae (3.2+45) [Installed]
linux-headers-686-pae
(The first two lines are a single command, split for readability).
This shows that linux-headers-3.2.0-3-686-pae
was dragged in by linux-headers-686-pae
, which in turn does not have any reverse dependencies on my system. Look at man apt-rdepends
for available switches.
Update: To expand a bit: it is not really useful to know exactly which package A dragged in package B, since package C which also depends on B might have been installed since, and thus removing A should not/will not remove B. apt-rdepends
would in this case list that both A and C depend on B, but give no indication whether A or C were originally responsible for the installation of B.