Nov23
Command Line Help From Apropos

Command Line Help From Apropos

One of the complaints I hear most often from new users about the Linux command line is how difficult it is to figure out. While with a GUI, a user can usually mouse around the interface and eventually find a program or option they are looking for, the BASH command line doesn’t really offer many clues as to how to perform the various tasks you may want to.

Fortunately there’s a tool to help with that: Apropos. Apropos uses the manual pages that you would usually read using the man command, and scans through their names, arguments and description to build a list of keywords. You can then use Apropos to search through these manual pages based on keywords rather than just the command name. This makes it much easier to find something you want to do; you can search for words related to the task you wish to perform rather than trying to find out the command name in advance, and Apropos will then suggest relevant commands to you. Being such a helpful tool, it also comes pre-installed in many distributions, so you can get started straight away.

Using Apropos

Usage is fairly simple as the following example shows:

apropos directory

In this example, apropos will show you all the commands that reference directories. In this case it’s quite a big list. The output consists of the name of the command on the left and a short description of its function on the right. You can also use multiple keywords with your search. So, let’s imagine you want to know how to create directory:

apropos create directory

The initial downside is that’s just made the list even longer. The default behavior for apropos is to treat each search keyword in isolation so you get all of the commands that contain change, and all the ones that contain directory. Fortunately there is a flag to change this behavior which can be used so that both keywords must be in the description:

apropos -a create directory

This makes the list much smaller and easier to find the command you need. You can also add more search keywords if you want to narrow the search down even further.

Another handy feature of Apropos is the ability to use wildcards. These are characters such as ? that can mean any single character, or * which can mean multiple characters. This means that if you can think of a term you are searching for, but are unsure of or don’t know the spelling, you can use the wildcard to replace the unknown characters. Again, this isn’t done by default, but through the addition of the -w flag, so using our example above:

apropos -w dir*y

As you can see from the result, this can again match a large number of commands, so it’s worth using with the -a flag to keep the number of matches down:

apropos -w -a create dir*y

A final point to note is that you can also use regular expressions when specifying keywords. This is part of the default behavior, so will work without any flags. We won’t show an example here as regular expressions are fairly complex and outside the scope of this article, and if you know how to use them then it shouldn’t need much explaining.

Apropos is a really useful tool and one that could do with more promotion towards new Linux users. If you ever find yourself sitting at the command line pondering what command you need to perform the task you need, then this is the one you need to remember.

Need a web host with speed, resiliency and security? Contact VPS.NET today.

This article was brought to you by VPS.net, for dedicated server hosting, cloud servers and 24/7 support visit our site here vps.net

No Comments

over 200,000 servers launched

and counting worldwide...