apt-pedia

Here is an incomplete and badly sorted list of the most useful combinations of apt/dpkg I have been using lately.
Please remember that those command lines which start with a # need root pemissions.

Install/Remove

  • Install a package from a repository:
    # apt-get install package
  • Install a package in the current directory:
    # dpkg -i package
  • Uninstall a package (keep config files)
    # apt-get remove package
  • Completely uninstall a package
    # apt-get remove --purge package

Information

  • Get the content of a deb package (you must have it somewhere)
    $ dpkg -c package.deb
  • Get description of a deb package (you must have it somewhere)
    $ dpkg -f package.deb
  • Get the description of a package
    $ apt-cache showpkg package
  • Print which packages a given package depends on
    $ apt-cache depends package
  • Print which packages depends on a given package
    apt-cache rdepends package
  • List installed packages
    $ dpkg -l
  • List contents of an installed package
    $ dpkg -L package
  • List description of an installed package
    $ dpkg -s package

Search files/packages

  • Look for a package (search only in names)
    $ apt-cache search -n package
  • Look for a package (even in description fields)
    $ apt-cache package
  • Check if a given package is installed
    $ dpkg -l | grep ^ii | grep package
  • Check if an installed package contains a given file
    $ dpkg -L package | grep file
  • Find out which package provided a given file:
    $ dpkg -S `which file`
  • Find all the packages whose status has changed (i.e. installed/removed) in last #n days:
    $ find /var/lib/dpkg/info/ -name '*.list' -mtime -#n -exec stat {} -c "%y %n" \; | sort -n | awk 'BEGIN{FS="[./]"} {print $1,$7}'

    #n must be a valid positive integer. Minutes can be used in the place of days by replacing -mtime with -mmin.

  • Find the last #m packages whose status has changed (i.e. installed/removed) in last #n days:
    $ ls -ltr /var/lib/dpkg/info/*.list | tail -#m

    #m must be a valid positive integer.

Please, feel free to correct this list or add any other useful statement.

None
A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".