あれ!? コマンドが無い。インストールしたいけどどのパッケージをインストールすればいいの?
普段はRHEL使いなのでDistributionsが変わるといつも悩みます。
Ubuntuではapt-fileコマンドがありました。
Find Which Package Contains Specific File on Ubuntu 20.04 LTS
https://linuxhint.com/find_which_package_contains_specific_file_ubuntu/
Ubuntu has a lot of packages in the official package repository. It is really hard to find the package that you need to install unless you know the exact package name of the software/tool you’re trying to install. It becomes even harder if you want to find out which package to install to get a specific file (i.e. /etc/apache2/apache2.conf) or executable (i.e. /usr/bin/netstat) on Ubuntu.
そのものずばり。上記サイトを見ればすべて書かれているのですが備忘録として。
環境
・Ubuntu 20.04.3 LTS
・Kernel 5.11.0-43-generic
- apt-fileのインストール
- キャッシュの更新
- apt-file search
- apt-file list
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
rootlinks@Ubuntu20:~$ sudo apt info apt-file Package: apt-file Version: 3.2.2 Priority: optional Section: universe/admin Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: APT Development Team <deity@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 92.2 kB Depends: perl:any, apt (>= 1.3~exp1~), libapt-pkg-perl, liblist-moreutils-perl, libregexp-assemble-perl Breaks: apt-venv (<< 1.0.0-1~), command-not-found (<< 0.2.38-2~), devscripts (<< 2.15.10~) Download-Size: 27.6 kB APT-Manual-Installed: yes APT-Sources: http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 Packages Description: search for files within Debian packages (command-line interface) apt-file is a command line tool for searching files contained in packages for the APT packaging system. You can search in which package a file is included or list the contents of a package without installing or fetching it. |
1 2 3 4 5 6 7 8 9 10 11 12 |
rootlinks@Ubuntu20:~$ sudo apt update Hit:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease Hit:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease Hit:3 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease Hit:4 https://dl.google.com/linux/chrome/deb stable InRelease Hit:5 http://security.ubuntu.com/ubuntu focal-security InRelease Hit:6 http://archive.ubuntulinux.jp/ubuntu focal InRelease Hit:7 http://archive.ubuntulinux.jp/ubuntu-ja-non-free focal InRelease Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
rootlinks@Ubuntu20:~$ sudo apt install apt-file Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libfprint-2-tod1 libllvm10 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl The following NEW packages will be installed: apt-file libapt-pkg-perl libexporter-tiny-perl liblist-moreutils-perl libregexp-assemble-perl 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded. Need to get 265 kB of archives. After this operation, 806 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libapt-pkg-perl amd64 0.1.36build3 [68.5 kB] Get:2 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 libexporter-tiny-perl all 1.002001-1 [35.5 kB] Get:3 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 liblist-moreutils-perl amd64 0.416-1build5 [55.5 kB] Get:4 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 libregexp-assemble-perl all 0.36-1 [77.5 kB] Get:5 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 apt-file all 3.2.2 [27.6 kB] Fetched 265 kB in 0s (2517 kB/s) Selecting previously unselected package libapt-pkg-perl. (Reading database ... 165628 files and directories currently installed.) Preparing to unpack .../libapt-pkg-perl_0.1.36build3_amd64.deb ... Unpacking libapt-pkg-perl (0.1.36build3) ... Selecting previously unselected package libexporter-tiny-perl. Preparing to unpack .../libexporter-tiny-perl_1.002001-1_all.deb ... Unpacking libexporter-tiny-perl (1.002001-1) ... Selecting previously unselected package liblist-moreutils-perl. Preparing to unpack .../liblist-moreutils-perl_0.416-1build5_amd64.deb ... Unpacking liblist-moreutils-perl (0.416-1build5) ... Selecting previously unselected package libregexp-assemble-perl. Preparing to unpack .../libregexp-assemble-perl_0.36-1_all.deb ... Unpacking libregexp-assemble-perl (0.36-1) ... Selecting previously unselected package apt-file. Preparing to unpack .../apt-file_3.2.2_all.deb ... Unpacking apt-file (3.2.2) ... Setting up libapt-pkg-perl (0.1.36build3) ... Setting up libexporter-tiny-perl (1.002001-1) ... Setting up libregexp-assemble-perl (0.36-1) ... Setting up liblist-moreutils-perl (0.416-1build5) ... Setting up apt-file (3.2.2) ... The system-wide cache is empty. You may want to run 'apt-file update' as root to update the cache. Processing triggers for man-db (2.9.1-1) ... |
The following packages were automatically installed and are no longer required:
libfprint-2-tod1 libllvm10
Use ‘sudo apt autoremove’ to remove them.
必要ないファイルがあるから削除してってことなので。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
rootlinks@Ubuntu20:~$ sudo apt autoremove Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: libfprint-2-tod1 libllvm10 0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded. After this operation, 73.9 MB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 165750 files and directories currently installed.) Removing libfprint-2-tod1:amd64 (1:1.90.2+tod1-0ubuntu1~20.04.5) ... Removing libllvm10:amd64 (1:10.0.0-4ubuntu1) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ... |
インストール時のメッセージに”apt-file update”を実行してとあります。
The system-wide cache is empty. You may want to run ‘apt-file update’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
rootlinks@Ubuntu20:~$ sudo apt-file update Hit:1 http://jp.archive.ubuntu.com/ubuntu focal InRelease Hit:2 http://jp.archive.ubuntu.com/ubuntu focal-updates InRelease Hit:3 http://archive.ubuntulinux.jp/ubuntu focal InRelease Hit:4 http://archive.ubuntulinux.jp/ubuntu-ja-non-free focal InRelease Hit:5 http://jp.archive.ubuntu.com/ubuntu focal-backports InRelease Get:6 http://jp.archive.ubuntu.com/ubuntu focal amd64 Contents (deb) [40.9 MB] Hit:7 https://dl.google.com/linux/chrome/deb stable InRelease Hit:8 http://security.ubuntu.com/ubuntu focal-security InRelease Get:9 http://security.ubuntu.com/ubuntu focal-security i386 Contents (deb) [31.2 MB] Get:10 http://jp.archive.ubuntu.com/ubuntu focal i386 Contents (deb) [32.2 MB] Get:11 http://security.ubuntu.com/ubuntu focal-security amd64 Contents (deb) [71.3 MB] Get:12 http://jp.archive.ubuntu.com/ubuntu focal-updates i386 Contents (deb) [35.7 MB] Get:13 http://jp.archive.ubuntu.com/ubuntu focal-updates amd64 Contents (deb) [80.2 MB] Get:14 http://jp.archive.ubuntu.com/ubuntu focal-backports i386 Contents (deb) [721 kB] Get:15 http://jp.archive.ubuntu.com/ubuntu focal-backports amd64 Contents (deb) [735 kB] Fetched 293 MB in 34s (8560 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. |
routeコマンドを探してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
rootlinks@Ubuntu20:~$ apt-file search route | head acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/generic-modules/routecontrol.lisp acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/generic-modules/router.lisp acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/instantiations/routecontrol/spidergon/routecontrol.lisp acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/instantiations/routecontrol/xy/routecontrol.lisp acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/instantiations/router/XY-circuit/router.lisp acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/instantiations/router/XY-packet/router.lisp acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/instantiations/router/XY-wormhole/router.lisp acl2-books-source: /usr/share/acl2-8.2dfsg/books/workshops/2009/vandenbroek-schmaltz/GeNoC/instantiations/router/spidergon/router.lisp adwaita-icon-theme: /usr/share/icons/Adwaita/scalable/status/network-cellular-no-route-symbolic.svg adwaita-icon-theme: /usr/share/icons/Adwaita/scalable/status/network-no-route-symbolic.svg (snip) znc: /usr/share/locale/es_ES/LC_MESSAGES/znc-route_replies.mo znc: /usr/share/locale/fr_FR/LC_MESSAGES/znc-route_replies.mo znc: /usr/share/locale/id_ID/LC_MESSAGES/znc-route_replies.mo znc: /usr/share/locale/it_IT/LC_MESSAGES/znc-route_replies.mo znc: /usr/share/locale/nl_NL/LC_MESSAGES/znc-route_replies.mo znc: /usr/share/locale/pt_BR/LC_MESSAGES/znc-route_replies.mo znc: /usr/share/locale/ru_RU/LC_MESSAGES/znc-route_replies.mo zoneminder: /usr/share/zoneminder/www/api/app/Config/routes.php zsh-common: /usr/share/zsh/functions/Completion/Unix/_route zsh-common: /usr/share/zsh/functions/Completion/Unix/_tcptraceroute |
あれ!? 思っていたのと違う(^^;;
1 2 |
rootlinks@Ubuntu20:~$ apt-file search route | wc 26864 53746 2869429 |
26864行がヒット
1 2 3 4 5 6 7 8 |
rootlinks@Ubuntu20:~$ apt-file search '/route' | wc 11699 23398 1300054 rootlinks@Ubuntu20:~$ apt-file search 'bin/route' | wc 3 6 75 rootlinks@Ubuntu20:~$ apt-file search 'bin/route' iproute2: /usr/bin/routef iproute2: /usr/bin/routel net-tools: /sbin/route |
正規表現(-x)を使うと
1 2 3 4 |
rootlinks@Ubuntu20:~$ apt-file search -x '.*bin/route$' | wc 1 2 23 rootlinks@Ubuntu20:~$ apt-file search -x '.*bin/route$' net-tools: /sbin/route |
大文字小文字を区別しない(-i)
1 2 3 4 |
rootlinks@Ubuntu20:~$ apt-file search -i 'Bin/Route' iproute2: /usr/bin/routef iproute2: /usr/bin/routel net-tools: /sbin/route |
工夫が必要ですね。
パッケージのファイルリストを表示します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
rootlinks@Ubuntu20:~$ apt-file list net-tools net-tools: /bin/netstat net-tools: /sbin/ifconfig net-tools: /sbin/ipmaddr net-tools: /sbin/iptunnel net-tools: /sbin/mii-tool net-tools: /sbin/nameif net-tools: /sbin/plipconfig net-tools: /sbin/rarp net-tools: /sbin/route net-tools: /sbin/slattach net-tools: /usr/sbin/arp net-tools: /usr/share/doc/net-tools/NEWS.Debian.gz net-tools: /usr/share/doc/net-tools/README net-tools: /usr/share/doc/net-tools/TODO net-tools: /usr/share/doc/net-tools/changelog.Debian.gz net-tools: /usr/share/doc/net-tools/copyright net-tools: /usr/share/man/de/man5/ethers.5.gz net-tools: /usr/share/man/de/man8/arp.8.gz net-tools: /usr/share/man/de/man8/ifconfig.8.gz net-tools: /usr/share/man/de/man8/netstat.8.gz net-tools: /usr/share/man/de/man8/plipconfig.8.gz net-tools: /usr/share/man/de/man8/rarp.8.gz net-tools: /usr/share/man/de/man8/route.8.gz net-tools: /usr/share/man/de/man8/slattach.8.gz net-tools: /usr/share/man/fr/man5/ethers.5.gz net-tools: /usr/share/man/fr/man8/arp.8.gz net-tools: /usr/share/man/fr/man8/ifconfig.8.gz net-tools: /usr/share/man/fr/man8/netstat.8.gz net-tools: /usr/share/man/fr/man8/plipconfig.8.gz net-tools: /usr/share/man/fr/man8/rarp.8.gz net-tools: /usr/share/man/fr/man8/route.8.gz net-tools: /usr/share/man/fr/man8/slattach.8.gz net-tools: /usr/share/man/man5/ethers.5.gz net-tools: /usr/share/man/man8/arp.8.gz net-tools: /usr/share/man/man8/ifconfig.8.gz net-tools: /usr/share/man/man8/iptunnel.8.gz net-tools: /usr/share/man/man8/mii-tool.8.gz net-tools: /usr/share/man/man8/nameif.8.gz net-tools: /usr/share/man/man8/netstat.8.gz net-tools: /usr/share/man/man8/plipconfig.8.gz net-tools: /usr/share/man/man8/rarp.8.gz net-tools: /usr/share/man/man8/route.8.gz net-tools: /usr/share/man/man8/slattach.8.gz net-tools: /usr/share/man/pt_BR/man8/arp.8.gz net-tools: /usr/share/man/pt_BR/man8/ifconfig.8.gz net-tools: /usr/share/man/pt_BR/man8/netstat.8.gz net-tools: /usr/share/man/pt_BR/man8/rarp.8.gz net-tools: /usr/share/man/pt_BR/man8/route.8.gz |
help
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
rootlinks@Ubuntu20:~$ apt-file -h apt-file [options] action [pattern] apt-file [options] -f action <file> apt-file [options] -D action <debfile> Pattern options: ================ --fixed-string -F Do not expand pattern --from-deb -D Use file list of .deb package(s) as patterns; implies -F --from-file -f Read patterns from file(s), one per line (use '-' for stdin) --ignore-case -i Ignore case distinctions --regexp -x pattern is a regular expression --substring-match pattern is a substring (no glob/regex) Search filter options: ====================== --architecture -a <arch> Use specific architecture [L] --index-names -I <names> Only search indices listed in <names> [L] --filter-suites <suites> Only search indices for the listed <suites> [L] (E.g. "unstable") --filter-origins <origins> Only search indices from <origins> [L] (E.g. "Debian") Other options: ============== --config -c <file> Parse the given APT config file [R] --option -o <A::B>=<V> Set the APT config option A::B to "V" [R] --package-only -l Only display packages name --verbose -v run in verbose mode [R] --help -h Show this help. -- End of options (necessary if pattern starts with a '-') [L]: Takes a comma-separated list of values. [R]: The option can be used repeatedly Action: list|show <pattern> List files in packages list-indices List indices configured in APT. search|find <pattern> Search files in packages update Fetch Contents files from apt-sources. |