Download Article
Quick and easy ways to search for patterns using Grep
Download Article
If you want to search for a string of text in a file on Linux, the grep command will come in handy. Grep works the same in all versions of Unix, including the Mac Terminal and Windows Subsystem for Linux. This wikiHow article will teach you how to use grep in any version of Linux or Unix, including syntax tips and useful examples.
Things You Should Know
- The syntax to use grep on Linux is kbd|grep [options] "string of text" /path/to/file .
- The grep command is case-sensitive, but you can use grep -i to ignore case.
- To search for text in all files within a directory and its subdirectories, use grep -R to perform a recursive search.
Steps
Expert Q&A
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement
Tips
- You can use grep with the pipe symbol | to parse the results of other commands. For example, if you're using Ubuntu or another Debian-based Linux, apt list --installed | grep -i python will display a list of all installed packages containing the word "python" in their names or paths.Thanks
- When using grep, most shells will display matching terms in a different color than the other characters from the line. If yours doesn't, you can use grep --color -i "string of text" filename.txt .Thanks
- To see a list of all grep options, use the command man grep .Thanks
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement
References
About This Article
Thanks to all authors for creating a page that has been read 8,645 times.
Advertisement