How to use apropos Command in Linux

apropos Command in Linux: Complete Explanation with Examples

As a Linux user, if you have a problem remembering an exact command, this guide is what you need. When you need a specific Linux command, but you cannot remember it, the apropos command is a good helper. The apropos command in Linux looks for instructions using keywords that are supplied to it in the command line on all manual pages. These terms may appear in the command names or in descriptions of the functions they perform.

As you may know, the Man pages describe command functions and list applicable arguments. The apropos command helps you find your considered command using its man pages. Take a look at this tutorial to learn more about the apropos command in Linux and check out some examples to see how you can use it in different scenarios.

What is apropos Command & How to Use it?

There are hundreds of commands available in Linux, and it might be challenging to remember them all. Therefore, you can occasionally be unable to recall one when you need it. apropos command in Linux can be used in situations like this. When given keywords in the command line, apropos searches every manual page for those commands. These keywords may appear in command names or in explanations of their functions. This command-line tool is an excellent tool for discovering commands quickly, especially if you can’t recall the actual name of the command. The apropos command is not case-sensitive.

The apropos command in Linux does not work without a search term (keyword). It has the following simple syntax: about <keyword>

For instance, you can use the command below to look up all commands with the word “network”

apropos network

With a brief description of each command, this will provide a list of all commands with the keyword “network” in their names.

If you run a command with no keyword, you will face the below output:

apropos what?

As we mentioned earlier, it is because the apropos command in Linux searches for a keyword in names and descriptions of man pages.

Prerequisites to Use apropos Command in Linux

To let this tutorial works correctly, provide the options below and move on.

  • A Server running Linux VPS.
  • A non-root user with sudo privileges.
  • Access to the terminal.

Most Used Examples of apropos Command

So far, you got familiar with the apropos command in Linux which is helpful when a Linux user cannot remember a specific command. Also, to find a related command to complete an action, searching the command by a keyword can solve the problem. To find out all the situations that the apropos command can help you, stay with us and review the following apropos Linux Command Examples.

Example 1. Search for all Commands Related to a Keyword

As you learned, the apropos main usage is to find a single keyword in man pages. To find examples mentioning the keyword list, run the following command and view all instances of list in names and descriptions:

apropos list

Note: If you are unsure of the exact command name but know a keyword that could be used in the command, use the ‘-k‘ option. For instance, the command apropos -k “search pattern” will return all commands associated with pattern searching.

Example 2. Search for two Keywords

The apropos produces many results when the term is too broad.  for example, the apropos command in Linux prints 300 lines for a list. To reduce the number of matches, include another variable. For example, use the keywords list and directories, to get a list of all the directories.

Since apropos searches man pages that include list or directory when it comes with no arguments, you can use -a: to guarantee both are included in the output.

apropos -a list directory

To view a similar output without -a, use double quotes as you see in the command below.

apropos "list directory"

Example 3. Search for one of two Parameters

the apropos command in Linux can also be used to find man pages including any considered keywords. For example, you can use the following command to find their man pages.

apropos delete terminate remove

In this way, you will find the ”delete”, ”terminate”, and ”remove” search terms to find man pages including any of these keywords.

apropos delete terminate remove

The apropos command outputs lines with one or more keyword lines.

Example 4. Search for Multiple Keywords

To use part of the description as search terms, you can type it into the command line. But you must include them in quotes if you want to send more than one keyword to apropos.

apropos "remove files"

The apropos command in Linux scans the manual pages for commands whose descriptions contain matches for at least one of the keywords supplied to apropos when several keywords are passed to it without quotations. You learned how to use quotes to tell the apropos command in Linux to treat each word as a separate keyword variable in the above example, but you can also get the same result by using the -a command line option.

apropos -a remove files or directories

As you guess, despite leaving out the quotations, the syntax above will provide the exact same results as the previous example.

Example 5. Search for Exact Match

If you can just remember individual keywords or a part of the word, the apropos command in Linux is capable to find an exact match. For example, to find all the commands that match with set, run:

apropos set

The result displays instances of set that are present in strings like settings and offset. Use the -e flag to search for exact matches for set:

apropos -e set

Example 6. Search for Particular Sections

Each command has a man page with nine sections. By default, the apropos command in Linux looks for the keyword in any section. Use the -s prefix and the section number(s) to select the manual section to search within.

For example, run the following command to find list in sections 3 and 5:

apropos -s 3,5 list

Obviously, man pages including list in sections 3 or 5 will be printed.

Example 7. Search for a Specific Command

You may need to do an action on your Linux system, but you have no idea what command should be your choice. For example, if you don’t know how to compress a file, you can execute the following command in the terminal, which will display all related commands along with a brief explanation of each one’s capabilities.

apropos compress

Example 8. Regex Symbols Usages

You can use regex symbols to achieve some useful results and more options. One of them is to speed up the search process and filter results. For example, you can run a command like the below to search for all man pages starting with the word list:

apropos '^list'

Also, you can use the following command to search for any man page which includes zipcloak, zipnote, or zipinfo:

apropos "zip(note|cloak|info)"

In this way, the apropos command in Linux searches for zip with the cloak, note, or info suffix.

And you can use regex to carry out a more focused search. For example, you can execute the following command to find implementation, devices, or users in sections 3 or 5 on any man page that starts with list:

apropos -a -s 3,5 "^list" "(implementation|devices|users)"

Example 9. Display the Full Length of a Command’s Description

Since the apropos command trims the description in output by default, you can see that the output ends in an ellipsis and despite the window size, the trim is evident after running apropos with list.

You can use the -l option to avoid the apropos command to trim the description:

apropos list -l

In this way, the long descriptions of apropos in output will not be trimmed by default.

Example 10. Search for all Available Options for a Command

You can occasionally want to discover every choice that applies to a particular command. To find a command, use the apropos command in Linux. Then, use the man command to view all the options. So, you can use the scenario of wanting to find every ls command option. You can enter the command by typing:

apropos ls

Now, to see all available options for ‘ls’ command, run:

man ls

Once you view the manual page for ‘ls’ command, you can receive a list of all available options along with their descriptions.

Example 11. Search for a Particular Syntax/Usage

You may occasionally know the name of the command you require but not its precise syntax or usage. In this situation, you can use the ‘apropos’ command to locate the necessary command. Take the ‘grep’ command as an example. You want to use it, but you can’t recall the syntax. You can enter the command by typing:

apropos grep

The’man’ command can then be used to find out more about the ‘grep’ command and how to utilize it.

Note: You can use the ‘-w‘ option to only look for commands that exactly match your search query. For instance, apropos -w grep will only return the command ‘grep’ and not other commands that contain the term “grep”.

Example 12. Search for Commands related to a Specific Pattern

To find commands related to a particular pattern, the ‘apropos’ command can also be used in combination with wildcards. When you want to locate all commands connected to a specific kind of file or operation, this can be quite helpful. For example, you can use the following command to locate all commands related to file compression:

apropos "*compress*"

‘gzip’, ‘bzip2’, ‘zip’, and a number of other file compression-related commands will all be returned by this.

Example 13. Search for all Commands related to Image Files

Similarly to the above previous command, you can use the apropos command in Linux to locate all commands pertaining to a particular file type. For example, you can use the command below to identify all commands linked to image files.

apropos "*image*"

All commands relating to image files, including “convert,” “identify,” “mogrify,” and others, will be returned by this.

How to Use apropos Command in Shell Scripting

Shell scripting can also make use of the ‘apropos’ command. You can find the command you need in a shell script by using the ‘apropos’ command, then use it in your script. Let’s take the scenario where you are building a shell script that needs to look for a particular pattern in a file. To locate the ‘grep’ command and utilize it in your script, use the ‘apropos’ command.

What are apropos Command Alternatives?

There are various alternate tools you can use in addition to the apropos command in Linux, which is a great tool for locating commands associated with a particular subject.

One of the apropos alternatives is the ‘whatis‘ command, which offers a succinct explanation of a certain command. For instance, you can type the below command to find out what the ‘ls’ command does.

whatis ls

The ‘man -k’ command, which functions similarly to the ‘apropos’ command is another apropos alternative. You can type the following command to look for instructions pertaining to a particular subject:

man -k <keyword>

With a brief description of each command, this will provide a list of all commands connected to the keyword you entered.

apropos Command Options in Linux

The apropos command functions without any arguments. Options still let you alter the result or the way you search. Standard options include:

OptionDescription
-eReturns names and descriptions that match the keyword exactly.
-dPrints debugging messages.
-wSearches for the keyword with wildcards.
-aFunctions as logical AND. Returns output when all the keywords match.
-lStops output trimming.
-CUses user-configuration files instead of the $MANPATH.
-sSearches only in specific man pages sections.
-MSets the search path to PATH rather than the default $MANPATH.
-mLooks for man page descriptions from other OSs.
-LSets the locale for the search.
-rInterprets each keyword as a regex.

FAQ

You may quickly and simply discover the commands you need with the help of the 'apropos' command, which is a strong and useful tool. The 'apropos' command can be useful when you're seeking for a certain command, trying to find all of a command's alternatives, or looking for commands that are relevant to a particular subject.

To achieve more results, use -a option. So, apropos -a network will return all commands related to "network".

Conclusion

In this article, you learned all about apropos command in Linux. As a Linux administrator or user, you may be familiar with Linux commands, but when it comes to memorizing all of them! No way. From now on, you know what to do when you face a situation that you need to use a specific command but you cannot remember it. You just need to not forget to use the apropos command in Linux for a quick search.

As some final tips, I can remind you to be as specific as possible when finding a command since apropos returns a lot of results. Also, do not forget to enclose multiple keywords in quotes to get the exact result related to all of them. While the apropos command in Linux returns the first 10 results, you can use ‘-a‘ option to see more results.

If you know any other apropos command in Linux, then the comment section is all yours.

Leave a Reply

Your email address will not be published. Required fields are marked.