Linux Tips - Debian/Ubuntu Searching for Software

in #linux7 years ago

Linux Tips - Debian/Ubuntu Searching for Software

sharp

You may already know about apt or apt-cache but did you know about apt-file? This is a quick tip on finding software to install on a Debian-based Linux distribution (such as Ubuntu) using the command line.

Example output here was on my Devuan arm system, so if you follow along with the commands on an Ubuntu or other system, the output may look a little different, but it all works the same.

apt-cache and apt

For those not familiar with apt-cache, it's a utility for querying the available software list for a software package based on its name or its description. For example, you might look for an awesome game like Slash'em by doing the following query:

apt-cache search slashem

And here's an example of what you might see as output:

slashem - variant of Nethack
slashem-common - files common to all slashem-packages
slashem-gtk - variant of Nethack (Gtk window port)
slashem-sdl - variant of Nethack (SDL window port)
slashem-x11 - variant of Nethack (X11 window port)

On the left is the package name, and then after the hyphen is a short description of that package.

The apt utility is a kitchen sink attempt to merge the different apt tools into a common interface. Its output is generally more aesthetically pleasing. Anyway, similar output results if you do apt search slashem:

Sorting...
Full Text Search...
slashem/stable 0.0.7E7F3-7 armhf
  variant of Nethack

slashem-common/stable,now 0.0.7E7F3-7 armhf [installed,automatic]
  files common to all slashem-packages

slashem-gtk/stable 0.0.7E7F3-7 armhf
  variant of Nethack (Gtk window port)

slashem-sdl/stable,now 0.0.7E7F3-7 armhf [installed]
  variant of Nethack (SDL window port)

slashem-x11/stable 0.0.7E7F3-7 armhf
  variant of Nethack (X11 window port)

Output here is similar to apt-cache but includes version information and the architecture along with the name and description.

Now, that's probably sufficient for about eighty percent of the time, but what if the thing you're searching on doesn't appear in the name or the description? For example, what if I wanted to install the venerable xclipboard? Let's search and see:

apt-cache search xclipboard

The command returns with no output. That's where apt-file comes into play.

apt-file

In the example of xclipboard, the package that contains the program doesn't mention the command name in either its name or its description, so apt-cache is useless. To search instead for any package that contains the string xclipboard in any of the files it installs, use the apt-file command. For example:

apt-file search xclipboard

And the output will look something like this:

lxsession: /usr/bin/lxclipboard
lxsession: /usr/share/man/man1/lxclipboard.1.gz
x11-apps: /usr/bin/xclipboard
x11-apps: /usr/share/man/man1/xclipboard.1.gz

Here the format of the output is the package name, followed by a colon, followed by the file name in that package that matched on the query string. For slightly better results, just like with apt/apt-cache you can use a regular expression. In the case of apt-file, it needs to be a Perl-formatted expression and the -x flag needs to be passed. So, to search on exactly xclipboard:

apt-file -x search '\bxclipboard\b'

And the output:

x11-apps: /usr/bin/xclipboard
x11-apps: /usr/share/man/man1/xclipboard.1.gz

Here we can see that the package x11-apps contains the xclipboard executable and its man page, so its a safe bet that it's the one I wanted.

Command not found?

Depending on your system, you may not already have apt-file installed. So, before you can use it, you will need to install it and update the package cache. For example:

sudo apt-get install apt-file
apt-file update

There are a few caveats with that update command. If you run it as root it will update the system wide cache and any user, including root will be able to use the command to search for packages. If you run it as your normal user, then only that user's cache will be updated, and no one else, including root, will be able to search for packages unless they update their respective package caches.

Summary

In short, you can use apt-file to look for software packages that contain a specified substring and it supports regular expressions for more specific matching. This search is against a package cache of available software to be installed, results have nothing to do with what is already installed on your system.

References


Other tips:

~~ Thanks for Reading ~~

Sort:  

Nice article. I like to do
$ apt-cache search pip | grep pip for example to refine the returned results

Yeah, that does help to cut down a bit on false positives.

Btw check my subreddit I started reddit.com/r/linux_mentor would be cool if you can post this article on there.

Coin Marketplace

STEEM 0.22
TRX 0.27
JST 0.041
BTC 103833.33
ETH 3841.42
SBD 3.30