Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep multiple extension current and subfolders

Tags:

grep

I'm trying to grep multiple extensions within the current and all sub-folders.

grep -i -r -n 'hello' somepath/*.{php,html}

This is only grepping the current folder but not sub-folders.

What would be a good way of doing this?

like image 531
Mike Avatar asked Oct 28 '09 20:10

Mike


People also ask

How do I grep in a folder and subdirectories?

To include all subdirectories in a search, add the -r operator to the grep command. This command prints the matches for all files in the current directory, subdirectories, and the exact path with the filename. In the example below, we also added the -w operator to show whole words, but the output form is the same.

How do I grep for a specific file extension?

Only Including Certain Files in grep Searches By default, grep will search all files in a given folder and its subfolders if you invoke it with the recursive -r flag. This will pick up everything, but if you only want certain extensions, the option you'll want to use is --include.

How do I grep all log files?

For searching files, the command syntax you use is grep [options] [pattern] [file] , where “pattern” is what you want to search for. For example, to search for the word “error” in the log file, you would enter grep 'error' junglediskserver. log , and all lines that contain”error” will output to the screen.


1 Answers

Using only grep:

grep -irn --include='*.php' --include='*.html' 'hello' somepath/
like image 129
Bryan Head Avatar answered Oct 11 '22 14:10

Bryan Head