Searching Within Manual Pages
In this step, you will learn how to search for specific information within manual pages, which is very useful when working with commands that have extensive documentation.
Let's access the manual page for the grep
command, which is used for pattern matching in files:
man grep
Once the manual page is open, you can search for specific text by:
- Pressing
/
(forward slash)
- Typing your search term
- Pressing
Enter
Let's try searching for information about the -i
option by typing:
/\-i
After pressing Enter
, the manual page will jump to the first occurrence of -i
. You can find the next occurrence by pressing n
, or go back to the previous occurrence by pressing N
.
The -i
option makes grep
ignore case distinctions, which means it will match uppercase and lowercase letters alike.
You can also search backward through the document by pressing ?
instead of /
, typing your search term, and pressing Enter
.
Let's add what we've learned about searching to our commands.txt file. Exit the manual page first by pressing q
, then:
echo "Searching in man pages: / (forward) or ? (backward), n (next), N (previous)" >> commands.txt
echo "grep - search for patterns in files" >> commands.txt
echo " -i option: ignore case distinctions" >> commands.txt
Now, let's practice by looking up information about the find
command, which is used to search for files in a directory hierarchy:
man find
Take a moment to explore this manual page. Search for information about the -name
option, which allows you to search for files by name:
/-name
Exit the manual page when you're done and add what you've learned to our commands.txt file:
echo "find - search for files in a directory hierarchy" >> commands.txt
echo " -name option: search for files by name" >> commands.txt