Ubuntu Package Origin: Find Which Package a File Belongs To

Locating the Origin of Files and Utilities
Have you ever encountered a file within a directory and questioned its source? Perhaps you're guiding someone on using a specific tool, only to realize you've forgotten which package provided it.
While a web search might offer answers, wouldn't you prefer a direct solution? Consider installing the dlocate utility, a more efficient alternative to dpkg for these types of inquiries.
Installation
The installation process is straightforward, utilizing the apt package manager:
sudo apt-get install dlocate
Basic Usage
To utilize the command, employ the syntax 'dlocate '. This will generate a list of potential matches.
$ dlocate flac libxine1: /usr/lib/xine/plugins/1.1.4/xineplug_flac.so
libtunepimp5: /usr/lib/tunepimp/plugins/flac.tpp
gstreamer0.10-plugins-good: /usr/lib/gstreamer-0.10/libgstflac.so
flac: /.
flac: /usr
flac: /usr/bin
flac: /usr/bin/flac
----- trimmed ------
As demonstrated, the output can be extensive, displaying numerous partial filename matches. Providing the complete file path significantly improves accuracy.
Refining the Search
To pinpoint the exact package, determine the full path of the file using 'which '. Subsequently, input this path into dlocate.
$ which flac /usr/bin/flac $ dlocate /usr/bin/flac flac: /usr/bin/flac
This reveals that the flac command originates from the "flac" package. Even utilizing command substitution can streamline the process.
$ dlocate `which flac` flac: /usr/bin/flac
Alternative Method
If installing dlocate isn't preferred, the built-in 'dpkg -S ' command offers a similar function. However, its performance and output organization are not as refined.
Regardless of the chosen method, supplying the complete file path to either utility ensures optimal results.