July 08, 2008

How-To: Use apt-file to See What Files a Package Installs

Install apt-file

apt-file is a tool which allows you to see what files contains a package in the repositories, without the need to necessarily install it. It also allows searching for files inside packages. To get it on Debian Lenny, type as root:

apt-get install apt-file

Next, update the cache:

apt-file update

This will take a while.

Using apt-file

1. Search for a specific file in all the packages

apt-file search file_name

For example, try this:

apt-file search ogg123

ogg123 is a command line player for Ogg Vorbis included in the vorbis-tools package on Debian. However, if you don't know the exact name of the package but you know the tool's name (in this case, ogg123), you can search for it. Here's the output:

$ apt-file search ogg123
irssi-scripts: /usr/share/irssi/scripts/ogg123.pl
python-pyvorbis: /usr/share/doc/python-pyvorbis/examples/ogg123.py
vorbis-tools: /usr/bin/ogg123
vorbis-tools: /usr/share/doc/vorbis-tools/examples/ogg123rc-example
vorbis-tools: /usr/share/man/man1/ogg123.1.gz

So you can see that the package vorbis-tools contains the binary which will get installed as /usr/bin/ogg123.

Using apt-file to search for a specific file without knowing the exact package name

2. List files in a given package
Let's try to list all the files which a specific package will install. Here are the first entries from the output of the command apt-file show vorbis-tools:

$ apt-file show vorbis-tools
vorbis-tools: /usr/bin/ogg123
vorbis-tools: /usr/bin/oggdec
vorbis-tools: /usr/bin/oggenc
vorbis-tools: /usr/bin/ogginfo
vorbis-tools: /usr/bin/vcut
vorbis-tools: /usr/bin/vorbiscomment
vorbis-tools: /usr/bin/vorbistagedit

3. Purge the cache
To purge the cache generated by apt-file update, use:

apt-file purge

As root. You will have to create the cache again with apt-file update.

# apt-file purge

$ apt-file show amarok
E: The cache directory is empty. You need to run 'apt-file update' first.

For more details about apt-file, use the help and the manual page:

apt-file --help
man apt-file

Updated: Jul 08, 2008 (Created: Jul 08, 2008)


GiNeR said...

'dpkg -S' is more useful

Brian said...

dpkg -S only searches the packages that are already installed. dpkg can't answer the question "what package should I install to get this file", but apt-file can.