Grep command

(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:

  1. 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.
  2. It is absolutely the fastest way to search for text
  3. The -Hrn tells grep to search the subdirectories and display the results with line numbers
  4. The period at the end of the command tells grep to start looking in the current subdirectory
  5. 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.


This entry was posted in General Information and tagged . Bookmark the permalink.

Leave a Reply