Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I recursively grep all directories and subdirectories?

Tags:

linux

grep

unix

How do I recursively grep all directories and subdirectories?

find . | xargs grep "texthere" * 
like image 494
wpiri Avatar asked Jan 01 '10 05:01

wpiri


People also ask

How can I recursively grep through subdirectories?

Grep command is used to search text from files. It is a versatile pattern that invokes grep with –r. –R option search files recursively from subdirectories, starting from the current directory. The command is run from the top-level directory.

How do you grep all subdirectories?

To Search 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.

Can grep be instructed to look at every file in a directory and its subdirectories?

You can make grep search in all the files and all the subdirectories of the current directory using the -r recursive search option: grep -r search_term .

How do you recursively grep?

To recursively search for a pattern, invoke grep with the -r option (or --recursive ). When this option is used grep will search through all files in the specified directory, skipping the symlinks that are encountered recursively.


1 Answers

grep -r "texthere" . 

The first parameter represents the regular expression to search for, while the second one represents the directory that should be searched. In this case, . means the current directory.

Note: This works for GNU grep, and on some platforms like Solaris you must specifically use GNU grep as opposed to legacy implementation. For Solaris this is the ggrep command.

like image 60
Vinko Vrsalovic Avatar answered Oct 06 '22 23:10

Vinko Vrsalovic