In the past I used CentOS Linux the open source RedHat Enterprise Linux clone but these days I find myself using Ubuntu Linux more and more often because so many more packages that clients want installed are more up to date. One command I used to use on CentOS all the time was the yum whatprovides command which would allow me to search for specific applications, scripts, libraries, etc. to figure out what packages I needed to install. The command that is similar on Ubuntu is apt-file which does not come installed by default. Below I show the output of an example yum whatprovides command on CentOS Linux followed by what needs to be done to use apt-file on Ubuntu Linux.
Using yum whatprovides On CentOS Linux:
- [root@centos-dev ~]# yum whatprovides *bin/whois
- Loaded plugins: fastestmirror
- Loading mirror speeds from cached hostfile
- * atomic: www6.atomicorp.com
- * base: mirror.raystedman.net
- * epel: fedora-epel.mirror.lstn.net
- * extras: centos.mirror.lstn.net
- * rpmforge: mirror.us.leaseweb.net
- * updates: centos.mirror.lstn.net
- jwhois-3.2.3-12.el5.i386 : Internet whois/nicname client.
- Repo : base
- Matched from:
- Filename : /usr/bin/whois
- jwhois-3.2.3-12.el5.i386 : Internet whois/nicname client.
- Repo : installed
- Matched from:
- Filename : /usr/bin/whois
- [root@centos-dev ~]#
As you can see above after searching using the yum whatprovides command we have figured out that jwhois installs the whois command on CentOS. Now if we wanted to accomplish the same goal on Ubuntu for say Apache’s mod_ssl we would first need to install apt-file followed by creating the apt-file cache at which time we could then search the cache for the whois command which is shown in examples below.
Install apt-file On Ubuntu Linux:
- root@ubuntu-dev:~# apt-get install apt-file
- Reading package lists... Done
- Building dependency tree
- Reading state information... Done
- The following extra packages will be installed:
- libapt-pkg-perl libconfig-file-perl liblist-moreutils-perl libregexp-assemble-perl
- The following NEW packages will be installed:
- apt-file libapt-pkg-perl libconfig-file-perl liblist-moreutils-perl libregexp-assemble-perl
- 0 upgraded, 5 newly installed, 0 to remove and 40 not upgraded.
- Need to get 255 kB of archives.
- After this operation, 930 kB of additional disk space will be used.
- Do you want to continue [Y/n]? Y
- Fetched 255 kB in 1s (144 kB/s)
- Selecting previously unselected package libconfig-file-perl.
- (Reading database ... 70452 files and directories currently installed.)
- Unpacking libconfig-file-perl (from .../libconfig-file-perl_1.50-2_all.deb) ...
- Selecting previously unselected package libapt-pkg-perl.
- Unpacking libapt-pkg-perl (from .../libapt-pkg-perl_0.1.25build2_amd64.deb) ...
- Selecting previously unselected package liblist-moreutils-perl.
- Unpacking liblist-moreutils-perl (from .../liblist-moreutils-perl_0.33-1build1_amd64.deb) ...
- Selecting previously unselected package libregexp-assemble-perl.
- Unpacking libregexp-assemble-perl (from .../libregexp-assemble-perl_0.35-2_all.deb) ...
- Selecting previously unselected package apt-file.
- Unpacking apt-file (from .../apt-file_2.5.0ubuntu1_all.deb) ...
- Processing triggers for man-db ...
- fopen: Permission denied
- Setting up libconfig-file-perl (1.50-2) ...
- Setting up libapt-pkg-perl (0.1.25build2) ...
- Setting up liblist-moreutils-perl (0.33-1build1) ...
- Setting up libregexp-assemble-perl (0.35-2) ...
- Setting up apt-file (2.5.0ubuntu1) ...
- The system-wide cache is empty. You may want to run 'apt-file update'
- as root to update the cache. You can also run 'apt-file update' as
- normal user to use a cache in the user's home directory.
- root@ubuntu-dev:~#
Once apt-file is installed make sure to update the apt-file cache or you will receive the below warning and no results.
Update apt-file Cache Empty Warning On Ubuntu Linux:
- root@ubuntu-dev:~# apt-file list whois
- E: The cache is empty. You need to run 'apt-file update' first.
- root@ubuntu-dev:~#
Update apt-file Cache On Ubuntu Linux:
- root@ubuntu-dev:~# apt-file update
- Downloading complete file http://us.archive.ubuntu.com/ubuntu/dists/precise/Contents-amd64.gz
- % Total % Received % Xferd Average Speed Time Time Time Current
- Dload Upload Total Spent Left Speed
- 100 21.2M 100 21.2M 0 0 2092k 0 0:00:10 0:00:10 --:--:-- 2039k
- Downloading complete file http://us.archive.ubuntu.com/ubuntu/dists/precise-updates/Contents-amd64.gz
- % Total % Received % Xferd Average Speed Time Time Time Current
- Dload Upload Total Spent Left Speed
- 100 4672k 100 4672k 0 0 1662k 0 0:00:02 0:00:02 --:--:-- 1702k
- Downloading Index http://us.archive.ubuntu.com/ubuntu/dists/precise/Contents-amd64.diff/Index:
- No Index available.
- Downloading complete file http://us.archive.ubuntu.com/ubuntu/dists/precise/Contents-amd64.gz
- % Total % Received % Xferd Average Speed Time Time Time Current
- Dload Upload Total Spent Left Speed
- 0 21.2M 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Depending on the speed of your system and how many repos are configured this could take a little bit of time. Also the above example output was cut short as to not spam the entire page with apt-file cache updates. Once the apt-file cache has been updated you can proceed to search the cache for whatever you like including applications, scripts, libraries, packages, etc. as shown in the below example.
Search apt-file Cache On Ubuntu For whois Command:
- root@ubuntu-dev:~# apt-file search "bin/whois"
- whois: /usr/bin/whois
- root@ubuntu-dev:~#
As shown in the output of the above example you can see that the whois package is what installs the whois command on Ubuntu. It can really come in handy to have this capability on Ubuntu which again is similar to the yum whatprovides command on CentOS.