Advanced APT user tricks

Debian/Ubuntu apt-get tricks.

Basics

Install software

apt-get install foobar

Search software

apt-cache search foobar

You can query files to see which packages own them, or query packages to see which files own them.

Installing apt-file

apt-get install apt-file

Build apt-get file information cache

apt-file update

Query through the packages to determine which package contains the file

apt-file search mysqld

Query the other way around, you know the package name and would like info about all the files which are provided by a given pacage:

apt-file list mysqld

List all installed software/packages

dpkg --get-selections > software.txt

That will save your installed list to a file called software.txt. That list is every piece of software required to reproduce the state your PC is currently in.
Another way to get a full list of installed software is to run the command

dpkg --list

To restore a PC the list above

# dpkg --set-selections < software.txt
# apt-get dselect-upgrade

Clearing up space
Delete archived packages that are considered old.

# apt-get autoclean

Delete all archieved packages

# apt-get clean

Remove every file from a package

apt-get remove foobar --purge