Probing installed packages/files efficiently using dlocate command
It is crucial to efficiently probe packages and files that are already installed on your Linux system, like
- finding the package that a particular file on your system is belonging to,
- checking filenames that are contained in an already installed package.
Recently, I have found that using dlocate command rather than dpkg possibly boosts productivity in doing so. Compared to dpkg, dlocate excels particularly in
- search speed,
- search space,
- search with integrated regular expressions.
The following examples illustrate the differences between dlocate and dpkg. The examples are based on a scenario where we probe the anthy-el package (a Japanese input system for Emacs) that contains an elisp file anthy.el as part of it.
Example 1
Using dlocate, one can search in "package_name vs file_name" space with regular expressions:
$ dlocate 'anthy\.el' anthy-el: /usr/share/emacs/site-lisp/anthy/anthy.el
In the example, the file name anthy.el (which is owned by the anthy-el package) was matched.
Example 2
Using dlocate -l, one can search in "package_name vs package_description" space with regular expressions:
$ dlocate -l anthy Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name Version Description +++-===========================-===========================-======================================================================== ii anthy 9100h-0ubuntu1 input method for Japanese - backend, diction un anthy-cannadic(no description available) un anthy-cannadic-2ch (no description available) ii anthy-el 9100h-0ubuntu1 input method for Japanese - elisp frontend ii ibus-anthy 1.2.0.20090813-2 anthy engine for IBus ii libanthy0 9100h-0ubuntu1 input method for Japanese - runtime library un scim-anthy (no description available) rc uim-anthy 1:1.5.6-0ubuntu1 Anthy plugin for uim
Note that even not-installed packages are included in the search space which is not the case of dpkg -l.
Example 3
Using dpkg -l, one can search in "package_name" space, where only exact matches will be hit (regular expressions not available):
$ dpkg -l anthy Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Description +++-================================-================================-================================================================================ ii anthy 9100h-0ubuntu1 input method for Japanese - backend, dictionary and utility
Example 4
Using dpkg -l | grep, one can search in "package-vs-description" space. However, this is much slower than using dlocate, and not-installed packages are excluded in the search space:
$ dpkg -l | grep anthy ii anthy 9100h-0ubuntu1 input method for Japanese - backend, diction ii anthy-el 9100h-0ubuntu1 input method for Japanese - elisp frontend ii ibus-anthy 1.2.0.20090813-2 anthy engine for IBus ii libanthy0 9100h-0ubuntu1 input method for Japanese - runtime library rc uim-anthy 1:1.5.6-0ubuntu1 Anthy plugin for uim
Example 5
To show file names contained in a particular package, dlocate -L and dpkg -L work similarly. However, dlocate performs much faster.
The fastest way to show all files contained in the anthy package:
$ dlocate -L anthy
An equivalent, but slower way using dpkg:
$ dpkg -L anthy
Since the default search space of dlocate is the "package_name vs package_description" space, one can achieve approximately the same result by the following naive way:
$ dlocate anthy: