How to Search for Strings in man Pages

You can use the man command to find information about any command that you know the name of. However, you might have some difficulty if you don’t remember the name of the command. You might also be looking at a huge man page that’s extremely long, like the one for bash or mplayer, where it may be difficult to find what you’re looking for inside of the text. Fortunately, there are a few tricks that have you covered in this area.

You’ll want to start by opening up a terminal. You can search for the word terminal from the Ubuntu Unity Dash or hold Ctrl+Alt+T to get one opened. Xfce4, Cinnamon, KDE and LXDE users might want to select the Applications menu, hover over System Tools and then click or tap on Terminal to start up a command line environment.

Method 1:  Search for Strings inside a man Page

You have two options for searching, depending on whether or not you already have the man page open. The first involves you not being inside a page, so let’s say you’re at the command line and want to find some text. Type man bash | less +/newline to open the bash man page and then highlight every instance of the word newline in the text. It appears quite often, so you can push the n key to move forward to the next search result that comes up. If you want to go backward to one you’ve already seen, then just push Shift+n to move in the opposite direction.

Keep in mind that you could replace man with any valid man page name and the word newline with any string that you’d like to search for. We simply used this as an example because that word appears at many points in the man page article for the Bourne shell. Once you’re done looking things over, you can always exit the man page simply by typing the letter q in the same way that you would have whenever you’re using the man browser.

Method 2: Searching for Strings While Reading a man Page

You can also easily search whenever you’re in the process of reading a man page using much the same method you’d use in vi or in vim. Type man bash or the word man followed by the name of any command that you’d be interested in reading about. Once you’re inside of the man browser, type / followed by whichever word you’d like to find the next instance of. You can then push the enter or return key to search for it.

Just like with the first method, you can push n to move forward to the next instance or use Shift+n to move back one. Type another forward slash followed by another search term to reset the search. Since the man browser doesn’t keep or a search history or have any sort of real limitation in this respect, you can just keep issuing new searches for different words. This tends to be useful at times when you need to find several different command options in a fairly long piece.

Method 3: Testing a Command from Inside a man Page

If you’re reading the man page you were looking for and you wanted to give a command a try, then type ! followed by the command itself. Since the man command uses the less pager by default and less uses vi/vim bindings, you can run functions from it without switching to another console. Whatever the command does will be shown to you at the tail end of whatever the last output was in the previous screen you were working from before entering into man.

For instance, let’s imagine that you were reading the page for uname and wanted to try out some options. While you’re inside of the man browser, type !uname -oirv to get the same exact output you’d receive when you run it from a normal bash command line. This will work with nearly any command at all regardless of which man page you were looking at. It’s most useful, though, for trying something out while you’re looking at the instructions for it. If you’re working with something that takes a large number of options and want to see them at once, then you might want to maximize the window and then start typing away.

Once you’re done, simply push the return key and you’ll be back inside man.

Method 4: Searching for Commands You May Not Know the Name Of

This is all well and good if you want to search for strings in man pages and then test them out, but you’ll often find that you don’t know the name of a command. You can type appropos followed by any word to do a full search for everything that might involve said command. Let’s say you wanted to see what kinds of commands there are involving network configuration. Type apropos network and then push enter or return. You can also type man -k network to get the same exact output. This is a useful trick if you ever find yourself on a Linux system that doesn’t let you use appropos for these kinds of searches.

You’ll receive a whole page full of responses, which you can scroll up in your terminal to see. A mouse or trackpad scroll will work just fine, as would the Shift+Ctrl+PageUp and Shift+Ctrl+PageDown keyboard shortcuts. If you’re working from a virtual terminal that doesn’t allow you to scroll text, then issue apropos network | less and then scroll through the responses either with the cursor keys or by pushing the j key to go down and the k key to go backwards.

Keep in mind that the word network was merely an example and that you can replace it with anything you want to search for. This is great for any situation where you might have actually forgotten how to use a particular command.


Kevin Arrows

Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.