This article was reviewed by Luigi Oppido and by wikiHow staff writer, Nicole Levine, MFA. Luigi Oppido is the Owner and Operator of Pleasure Point Computers in Santa Cruz, California. Luigi has over 25 years of experience in general computer repair, data recovery, virus removal, and upgrades. He is also the host of the Computer Man Show! broadcasted on KSQD covering central California for over two years.
This article has been fact-checked, ensuring the accuracy of any cited facts and confirming the authority of its sources.
This article has been viewed 10,694 times.
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
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