Ubuntu であるバイナリがどのパッケージに含まれるか調べる方法

dpkg -S を使う方法

インストール済みのパッケージであれば、dpkg -S で調べられる。

$ dpkg -S uniq
apache2-bin: /usr/lib/apache2/modules/mod_unique_id.so
libstdc++-11-dev:amd64: /usr/include/c++/11/parallel/unique_copy.h
coreutils: /usr/share/man/man1/uniq.1.gz
libstdc++-11-dev:amd64: /usr/include/c++/11/bits/unique_ptr.h
libstdc++-11-dev:amd64: /usr/include/c++/11/bits/unique_lock.h
coreutils: /usr/bin/uniq
...

フルパス指定で検索

$ dpkg -S /usr/bin/uniq
coreutils: /usr/bin/uniq

/bin → /usr/bin にシンボリックリンクがあり、/bin と /usr/bin に同じバイナリがみえるが、coreutils の一部など、/bin 配下にインストールされるものは、そちらで調べる必要がある。
例えば、ls コマンドでは、/bin/ls を指定しないと見つからない。

$ dpkg -S /usr/bin/ls
dpkg-query: パターン /usr/bin/ls に一致するパスが見つかりません
$ dpkg -S /bin/ls
coreutils: /bin/ls

apt-file を使う方法

インストールされていないものでも、apt-file を使うと、すべてのパッケージ情報を取得したキャッシュから検索して調べられる。

apt-file インストール

# apt install apt-file

パッケージ情報取得

# apt-file update

使い方

$ apt-file search pstree 
criu: /usr/lib/python3/dist-packages/pycriu/images/pstree_pb2.py
manpages-ja: /usr/share/man/ja/man1/pstree.1.gz
psmisc: /usr/bin/pstree
psmisc: /usr/bin/pstree.x11
...

フルパス指定で検索

$ apt-file search /usr/bin/pstree
psmisc: /usr/bin/pstree                   
psmisc: /usr/bin/pstree.x11