(Please note, these are quite old notes about dpkg and comp. For example, I think that apt now tracks the packages also.)
I recommend you to useaptitude instead of apt-get, since it keeps track of the packages that were installed as a dependency only (thus removing those extra packages, when the parent package is removed). But anyway, here is a list of handy commands for package management in Debian.
apt-cache policy package | grep Installed
dpkg -S `locate somefile`
apt-cache search string
COLUMNS=120 dpkg -l | grep string
aptitude
aptitude search '~n ^atla ~n doc$'
dpkg -L package
apt-cache depends package
apt-cache rdepends package
sudo apt-get install -t unstable package
sudo apt-get --purge remove package
sudo update-alternatives --config java
dpkg --get-selections package
echo package hold | sudo dpkg --set-selections
echo package install | sudo dpkg --set-selectionsNote how impractical those commands are. The aptitude command would simply be
sudo aptitude (un)hold package
dpkg --get-selections > present-selections.txt
sudo dpkg --set-selections < edited-selections.txt sudo aptitude update && sudo aptitude upgrade
sudo apitude [un]hold package
shell:~$ dpigs 87608 sun-j2re1.5 76728 tetex-base 59512 tetex-doc 54692 acroread 50736 acroread-plugins 45844 linux-image-2.6.16-2-686 45168 linux-image-2.6.17-1-686 44016 linux-image-2.6.15-1-686 42412 tetex-extra 38504 linux-source-2.6.15
deborphan | xargs sudo apt-get remove --purge --assume-yesor
apt-get --purge remove $(deborphan --guess-all | grep -v libc6-i686)Note:
deborphan does not know, if the package was installed by you (therefore having perhaps no dependencies), so be careful when using the above commands.
One can also use orphaner, a frontend for deborphan for finding orphaned packages.
The packages debfoster and localepurge are useful to free wasted disk space. Note: debfoster is now officially deprecated. Use aptitude instead.
If you want to clean your system (after letting apt-get collect all the dependencies during the years since installing Debian), you can use debfoster. Run debfoster and answer the questions (for a couple of hours for the first time). Remove what you don't need. Then execute sudo debfoster2aptitude (in /usr/sbin/debfoster2aptitude), answer questions, then start using aptitude. The apt interface aptitude can keep track of automatically and non-automatically installed packages.
Also programs symlinks and cruft may be useful in maintaining the system. symlinks finds broken and messy symbolic links and cruft examines all files in the system:
sudo cruft -r cruftreport.txtLook also at Debian security scanner
debsecan.