Where ''is'' it? (in Debian)

Answers to these questions and more, for your Debian system...


By far and away the most common question in [http://hash-debian.leguin.org.uk Debian] is "Where is it?"

Fortunately, this is the sort of question that there are well-established methods of finding answers for.

Here are some of the many variations on that question, and their answers:

A word about the tools:

The tools I mention here (apropos, "msg apt" on ["?FreeNode"], dlocate, dpkg, find, grep, grep-available, locate, http:''/packages.debian.org/, whatis, whereis) all have many more options and much more power than that tiny bit I've shown here. For maximum enjoyment from these tools and others, please see their man pages.

"When I type {{{foo}}}, which file gets executed?"

Tools:

When you enter a program name at the command-line, the shell looks for an executable file of that name in a list of directories named by the environment variable PATH, and it runs the first matching executable it finds. You can view the current path by typing 'echo $PATH', and change it like any other environment variable (see your favourite shell documentation for details.)

The which command will show you the full path of the executable that would be run. There is also a whereis command that will tell you the location of both the program and its man page, but whereis searches only a fixed path and will not find things in local additions to your PATH.

The type command will show you information about commands that are not really executable files too. It is itself not a executable files but part of bash the usual shell in debian. For help try help type.

"Where is file {{{bar.baz}}} on my system?"

Tools:

  • locate bar.baz

  • find / -name bar.baz

The GNU find command is the swiss-army knife of filesystem searching tools, and has great powers that we won't even begin to touch upon here. But we can use it in its most basic capacity to find the location of a file, like so: 'find '' -name [=bar.baz]'. The '''' here is actually the starting directory, so if you have an idea of where to start looking, you can specify it here, and find won't waste its time searching the rest of the disk. For example, if you are only looking for a bar.baz in your home directory, you would use: 'find $HOME -name bar.baz'.

The locate command is also useful for this basic file-finding task, and it will often give you results much faster than find will. It makes use of a database of all filenames on the system, and since this information is already all in the database, it locate doesn't have to go out and search the whole disk like find does. The usage of locate is simply 'locate bar.baz'.

The downside of locate is that building this database of filenames has its price, so it's usually only done once a day (by a cron job). This means that if you're looking for a file that is less than one day old, you'll have to force the database to update by running the 'updatedb' command, or go back to using find.

Note that if the file you're looking for has been installed by the Debian packaging system, the tools used to answer the next question will often answer this one too, so you could use those instead.

"I have a file {{{quux}}} on my system, which package does it belong to?"

Tools:

  • dpkg -S quux

  • dlocate quux

If you would like to find out what Debian package a particular installed file is associated with, you may use either of these commands. The relationship between dlocate and dpkg -S is very much like the one between locate and find, above. dlocate is much faster, but is not always up-to-the-minute accurate with regards to newly installed files.

Note that dlocate does not come on all systems by default, so you may have to install it.

"I ''don't'' have file {{{quux}}} on my system, but I need it. Which package do I install?"

Tools:

Finding out about files you don't have tends to require going off-site. One source of information is the [http://www.debian.org/distrib/packages#search_contents handy-dandy webform at packages.debian.org]. If you're signed on to [http://www.openprojects.net/ Open Projects Network], you can also ask apt-the-IRC-bot with '/msg apt find quux'.

If you would like to be able to make queries on this information locally, you can get a Contents file which lists all the files in all the packages of a particular distribution. All Debian mirrors carry this file in the appropriate subdirectory under debian/dists/, and it's named "Contents-ARCH.gz", where ARCH is the name of your machine's architecture (e.g. i386 or powerpc). So to get the list of all files in every package of the testing distribution for the i386 architecture, you would get [http://http.us.debian.org/debian/dists/testing/Contents-i386.gz debian/dists/testing/Contents-i386.gz] from your favourite Debian mirror.

    <p>Once you have the Contents file, you can look for a particular
    file by typing '<kbd>zgrep <var class="filename">quux</var>
    Contents-*.gz</kbd>'.  [<kbd class="command">zgrep</kbd> is just
    <kbd class="command">grep</kbd> that lets you look through
    compressed files without gunzipping them first.]</p>

    <p class="nav">[ <a href="#questions">Back to Questions</a> ]</p>

    <h2 id="list">"I installed the <var class="filename">zort</var>
    package, now how do I know what <a name="list">files</a> it gave
    me?"</h2>

    <p>Tools:</p>
    
      * <kbd>dpkg -L <var class="filename">zort</var></kbd>
      * <kbd>dlocate -L <var class="filename">zort</var></kbd>
      * <kbd>cat /var/lib/dpkg/info/<var class="filename">zort</var>.list</kbd>

    <p>If you've just installed a package but aren't quite sure where
    to start with it, you can ask for a listing of all the files it
    just installed.  This way, you can find out the names of the
    documentation and executable files.</p>

    <p>Note that <kbd class="command">dlocate</kbd> does not come on
    all systems by default, so you may have to install it.</p>

    <p class="nav">[ <a href="#questions">Back to Questions</a> ]</p>

    <h2 id="conf">"What files are used for the <a name= "conf"
    >configuration</a> of the <var class="filename">troz</var> package?"</h2>

    <p>Tools:</p>
    
      * <kbd>dlocate -conf <var class="filename">troz</var></kbd>
      * <kbd>cat /var/lib/dpkg/info/<var class="filename">troz</var>.conffiles</kbd>

    <p>If you want to know which files a package gets its
    configuration settings from, this will tell you.  These files will
    be the ones to fiddle with to get the package tuned to your
    liking, although most packages do not <em>require</em> you to edit
    them.</p>

    <p>Configuration files are also special because, unlike the other
    files associated with a package, they are not deleted when the
    package is removed.  This lets you install, remove, upgrade,
    swicth between packages, and switch back when you change your
    mind, without ever losing your configuration.</p>

    <p>If you decide you're <em>really</em> done with a package,
    <em>purging</em> it (instead of removing) will clean out the
    configuration files too.</p>

    <p class="nav">[ <a href="#questions">Back to Questions</a> ]</p>

    <h2 id="available">"Which package has the <var class="filename">noot</var>
    <a name="available">stuff</a>?"</h2>

    <p>Tools:</p>
    
      * <a href="http://www.debian.org/distrib/packages#search_packages"
  • <kbd>apt-cache search <var class="filename">noot</var></kbd>

  • <kbd>grep-available <var class="filename">noot</var></kbd>

}}}

Perhaps you're looking for a package with, say, freecell, but you don't want to search by filename because you don't know the exact name of any file in the package. What you do want to do is to search the descriptions of available packages. Any of these methods will work. grep-available is actually just a different interface to apt-cache, but I find it to be a little more comfortably grep-like. grep-available doesn't come by default on all systems though, so you may have to install it.

"What program or function do I have that does {{{snork}}}?"

Tools:

  • apropos snork

Actually, this question can often be answered by using the tools mentioned for the previous one. It's really just an excuse for me to plug apropos. apropos searches through the one-line description of files or functions provided by that program's man page, and returns a list of things that look relevant. For example, if I wanted to see a list of all the utilities I have on my system for working with HTML files, I'd type 'apropos html'. For further details on any particular program, you can follow up by viewing its man page.


This page was originally written by KevinTurner on 2/25/2001. There are now other tools which either didn't exist at the time or he just didn't use (e.g. dpkg-iasearch and apt-file) which this document should be updated to reflect.


2002/12/08 18:51 UTC (via web): You should mention dpkg-www, it is great for newbie.


New to the wiki, I thought I'd do something useful so I completely reformatted this page so that the original HTML gobbleygook pasted by the creator was translated into wiki format that displays the page properly.

Still a bit more to fix - will do it after bathing baby!

2005-03-11: AndyMorris