Debian / Ubuntu Linux: Find Out What Package Provides a File

last updated in Categories , , ,

How do I find out what package provides a file called /bin/ls? I use the rpm -qf /bin/ls command under Red Hat Enterprise Linux to find out package name. Can you tell me the equivalent command for the same under Debian or Ubuntu Linux? How do I find the package that provides a file?

You can use various commands. The dpkg is a command line tool that you use to install, build, remove and manage Debian packages. dpkg maintains some usable information about available packages. The dpkg-query is a command line tool to see information about packages listed in the dpkg database. The apt-file is a command line tool for searching files in packages for the APT package management system.

Debian or Ubuntu Linux commands to find out which package owns a file:

  1. Open the terminal application
  2. Type the following command to find out what package provides /usr/bin/passwd file:
    dpkg -S /usr/bin/passwd
  3. Type the following command to find out what package provides /usr/bin/passwd file:
    dpkg -S /usr/bin/passwd
  4. Use apt-file package searching utility:
    apt-file search vim

Let us see how to use these three commands and examples to find out what package provides as file.

How to find the package that provides a file

You can search for a filename from installed packages using dpkg -S command. For example, find out package name for /bin/ls, enter:
$ dpkg -S /bin/ls
Sample output:

coreutils: /bin/ls

The -S or --search option search for a filename from installed packages. You can also obtain detailed status information about coreutils package, enter:
$ dpkg -s coreutils
Sample output:

Package: coreutils
Essential: yes
Status: install ok installed
Priority: required
Section: utils
Installed-Size: 9040
Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: i386
Version: 5.97-5.3ubuntu3
Replaces: textutils, shellutils, fileutils, stat, debianutils (<= 2.3.1), dpkg (<< 1.13.2)
Provides: textutils, shellutils, fileutils
Pre-Depends: libacl1 (>= 2.2.11-1), libc6 (>= 2.6-1), libselinux1 (>= 2.0.15)
Conflicts: stat
Description: The GNU core utilities
 This package contains the essential basic system utilities.
 .
 Specifically, this package includes:
 basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd df dir
 dircolors dirname du echo env expand expr factor false fmt fold groups head
 hostid id install join link ln logname ls md5sum mkdir mkfifo mknod mv nice nl
 nohup od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
 sha1sum seq shred sleep sort split stat stty sum sync tac tail tee test touch
 tr true tsort tty uname unexpand uniq unlink users vdir wc who whoami yes
Original-Maintainer: Michael Stone <mstone@debian.org>

dpkg-query command

You can also use dpkg-query command which is a tool to show information about packages listed in the dpkg database. The -S option search for a filename from installed packages. All standard shell wildchars can be used in the pattern. This command will not list extra files created by maintainer scripts, nor will it list alternatives.
$ dpkg-query -S '/bin/ls'
$ dpkg-query -S 'passwd*'
$ dpkg-query --search '/path/to/file'
$ dpkg-query --search '/usr/bin/passwd'
$ dpkg-query --search '/etc/passwd'

How to use apt-file for package searching on Debian/Ubuntu

You need to install apt-file command which is a command line tool for searching files in packages for the APT package management system:
$ sudo apt-get install apt-file
$ sudo apt-file update

To search in which package a file is included, enter:
$ apt-file search date
$ apt-file search kvm-ok

Sample outputs:

cpu-checker: /usr/sbin/kvm-ok
cpu-checker: /usr/share/man/man1/kvm-ok.1.gz

How do I search for files not installed on my Debian/Ubuntu system

Visit the following url:

Debian Linux find the package that provides a file
Debian Linux find the package that provides a file

Ubuntu Linux find the package that provides a file

Once you found the package name install it using the apt command or apt-get command:
$ sudo apt install pakageNameHere

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Share this on (or read 2 comments/add one below):

Join the discussion at www.nixcraft.com

Historical Comment Archive