apt-file indexes the contents of packages in your available repositories, so you can find which package contains a given file. For example, if an online guide tells you to use some program, apt-file search <program-name> can tell you which package(s) you need to install.

Usage

  1. install apt-file (see how to install packages)

  2. create your database, or update it for recent changes:
     apt-file update
    
  3. Search:
     apt-file search <filename>
    

For example, if you have installed a package that complains about a missing library called libmp3lame.so.0:

$ apt-file search libmp3lame.so.0
libmp3lame0: /usr/lib/x86_64-linux-gnu/libmp3lame.so.0

$ sudo apt install libmp3lame0
...

$ ls /usr/lib/x86_64-linux-gnu/libmp3lame.so.0
/usr/lib/x86_64-linux-gnu/libmp3lame.so.0

{i} apt-file tells us where the file will be installed, which can help work out which package is needed. For example, /usr/lib/x86_64-linux-gnu/libmp3lame.so.0 is for 64-bit programs - 32-bit programs need /usr/lib/i386-linux-gnu/libmp3lame.so.0 instead.

apt-file supports regex searches:

apt-file search -x "bin/dig$"
apt-file search -x "bin/file[sn]"

Listing files

apt-file can also list the contents of a package:

$ apt-file list libmp3lame0
libmp3lame0: /usr/lib/x86_64-linux-gnu/libmp3lame.so.0
libmp3lame0: /usr/lib/x86_64-linux-gnu/libmp3lame.so.0.0.0
libmp3lame0: /usr/share/doc/libmp3lame0/changelog.Debian.amd64.gz
libmp3lame0: /usr/share/doc/libmp3lame0/changelog.Debian.gz
libmp3lame0: /usr/share/doc/libmp3lame0/changelog.gz
libmp3lame0: /usr/share/doc/libmp3lame0/copyright

Alternative Method

You can use dpkg to find which package provides a file, or which files a package contains:

$ dpkg -S libmp3lame.so.0
libmp3lame0:amd64: /usr/lib/x86_64-linux-gnu/libmp3lame.so.0

$ dpkg -L libmp3lame0
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libmp3lame.so.0.0.0
/usr/share
/usr/share/doc
/usr/share/doc/libmp3lame0
/usr/share/doc/libmp3lame0/changelog.Debian.amd64.gz
/usr/share/doc/libmp3lame0/changelog.Debian.gz
/usr/share/doc/libmp3lame0/changelog.gz
/usr/share/doc/libmp3lame0/copyright
/usr/lib/x86_64-linux-gnu/libmp3lame.so.0

dpkg -S is slower than apt-file, while dpkg -L output includes directories associated with packages. Both of them examine only packages you've already installed, but neither require you to maintain a separate database.

{i} If you just want to search installed packages more quickly, consider dlocate instead of apt-file.


CategoryPackageManagement | CategorySoftware

AltStyle によって変換されたページ (->オリジナル) /