Translation(s): English - Italiano

(!) ?Discussion


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

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


One of the most common questions in Debian is "Where is it?"

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

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 also show you information about commands that are not really executable files. It is itself not an executable file but a shell builtin in bash, the usual shell in debian. For help try help type.

"Where is file 'bar.baz' on my system?"

Tools:

The GNU find command is the swiss-army knife of filesystem searching tools, and it has great powers that we won't even begin to touch upon here. 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 most filenames on the system (this is configurable), and since this information is already all in the database, 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 done only 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 (or /etc/cron.daily/find) 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:

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.

apt-file, although not the best way, can be used to find files on the system but it uses a database that may or may not be up-to-date. See the next section for more details.

"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 handy-dandy webform at packages.debian.org. If you're signed on to 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 debian/dists/testing/Contents-i386.gz from your favourite Debian mirror.

Once you have the Contents file, you can look for a particular file by typing 'zgrep quux Contents-<ARCH>.gz'. zgrep is just grep that lets you look through compressed files without gunzipping them first.

There is also a tool that does something similar to the method described above: apt-file. You can apt-get install apt-file then apt-file update to update its database (needed only once in a while). Then you can do apt-file search quux to find a list of all packages that contain a file with the regular expression 'quux' in it. The advantage of this method is it's a debian tool, it's easier to maintain, it's easier to use and it works off-line. (ie. no network is needed as when using packages.debian.org).

"I installed the 'zort' package, now how do I know what files it gave me?"

Tools:

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.

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

What files are used for the configuration of the 'troz' package?

Tools:

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 require you to edit them.

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, switch between packages, then switch back when you change your mind, without ever losing your configuration.

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

"Which package has the 'noot' stuff?"

Tools:

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:

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.

2005-03-11: AndyMorris


?CategoryCommandLine