How To Wiki

Howto use find with grep to search into files in unix-like operating systems

1,795pages on
this wiki
Add New Page
Add New Page Talk0

grep command and the find command

Commands to type Edit

find . -exec grep -l "tosearch" {} \; 2> /dev/null
find . -name "*.txt" -type f -exec grep -l "tosearch" {} \; 2> /dev/null

Commands to type if you want to ignore the file type Edit

grep -r "tosearch"

A simple script Edit

You can use the following simple script named grind (grep + find):

#!/usr/bin/env perl
$arg = $ARGV[0];
$typ = $ARGV[1];
if ($typ eq "") {$typ = "*"};
print("\n***************\"$arg\" in files \"$typ\"****************\n");
$txt = "find . -name \"$typ\" -type f -exec grep -l \"$arg\" {} \\; 2> /dev/null";

Then you can use 'grind name "*.cpp"' to see all files . cpp that contain name. (a few bugs remain in the script)

From HowTo Wiki, a Wikia wiki.

Also on Fandom

Random Wiki