Fandom

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
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

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";
system("$txt");
print("\n");

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