(Last updated on: June 20, 2017)
Grep is a handy utility to find a text string within a file. Here is the command I use:
grep -Hrn "Payment and Delivery" .
There are some notes:
- Like everything else in the linux/unix/command line world, grep is case sensitive. If you want a case insensitive search, use the -i option.
- It is absolutely the fastest way to search for text
- The -Hrn tells grep to search the subdirectories and display the results with line numbers
- The period at the end of the command tells grep to start looking in the current subdirectory
- It is often useful to send the results to a text file with the “>” option – if you have permission. You can edit it with a text editor. If you do not have permission in your current subdirectory, you will have permission in your home subdirectory. The command will be changed to this:
grep -Hrn "Payment and Delivery" . > ~/temp.txt
vim ~/temp.txt
There’s also tons of information online.