Enterprise Linux Log

Jan 25 2008   10:11AM GMT

Apt-file: Providing apt’s answer to rpm -qf

Kutz Profile: Akutz

Anyone who has ever used rpm for package management has at one time or the other had to invoke the command:

rpm -qf PATH_TO_FILE

The above command will tell you what package manages the given file, or more specifically, what package was installed, when it was installed and what put that file on the hard drive. This is an incredibly useful feature when you are debugging a system, attempting to figure out where a file comes from, resolving version conflicts, etc. But many people do not realize that Debian derivatives, such as Ubuntu, also has a similar capability.

In your Debian derivative type:

sudo apt-get install apt-file

This command will install the helpful application apt-file onto your system. Once installed, take a look at its command line options by typing the eponymous command. This is what you will see:

apt-file version 

(c) 2002 Sebastien J. Grossapt-file [options] action [pattern] 

Configuration options: 

    --sources-list	-s  	sources.list location 

    --cache		-c  	Cache directory 

    --architecture	-a  	Use specific architecture 

    --cdrom-mount	-d  	Use specific cdrom mountpoint 

    --package-only	-l		Only display packages name 

    --fixed-string	-F		Do not expand pattern 

    --ignore-case	-i		Ignore case distinctions 

    --regexp		-x		pattern is a regular expression 

    --verbose		-v		run in verbose mode 

    --dummy		-y		run in dummy mode (no action) 

    --help		-h		Show this help. 

    --version		-V		Show version number 


    update			Fetch Contents files from apt-sources. 

    search|find		Search files in packages 

    list|show		List files in packages 

    purge			Remove cache files

As you can see, there are a lot of options. The option you need to mimic the functionality of rpm -qf is the search option. For example, to find out what debian package provides the application gpg simply type:

sudo apt-file search $(which gpg)

When you execute this command you are going to get a lot more results than you probably wanted. That is because the apt-file command does a lazy search and searches for any command that patches the pattern /usr/bin/gpg*. In order to narrow the results, use the –fixed-string option:

sudo apt-file search --fixed-string $(which gpg)

The console should display something similar to the following:

[0]akutz@vault:~$ sudo apt-file search --fixed-string $(which gpg) 

gnupg: usr/bin/gpg 

gnupg: usr/bin/gpg 

gnupg: usr/bin/gpg

I hope this little tutorial on apt-file will make your daily life as a Linux system administrator just a little bit easier!

3  Comments on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • Valdemar Lemche
    Erhm ... ok apt-file is cool, but debian/ubuntu's real equivalent to "rpm -qf ", which as has been in standard switch in any debian variant since ... well forever. Please remember that apt-get apt-file and all the other 'apt' associated programs are just wrapper programs around some package management program. For instance when I used redhat, (many years ago), I would always install apt-get as standard component to handle my RPM package management. (I can't live without apt ...)
    0 pointsBadges:
  • Valdemar Lemche
    Gr8 the point got stripped in the post ... :| What was meant to be written was: Erhm … ok apt-file is cool, but debian/ubuntu’s real equivalent to “rpm -qf “ is “dpkg -S“, which as has been in standard switch in any debian variant since … well forever.
    0 pointsBadges:
  • Schley Andrew Kutz
    I completely agree. I should have pointed out that the apt packages are just wrappers from the dpkg commands. I chose to focus on the apt packages for two reasons: - They are what Canonical are standardizing on for package management and IT administrators are likely to find the most help WRT package management if they ask about the apt tools. - The dpkg tools themselves are many. If there was just one dpkg command that did it all I would focus on that, but dpkg is really a suite of tools as well. Thank you again for your point, it just reinforces the fact that there is always more than one way to skin a doorknob.
    0 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: