Matt
Matt

Reputation: 106

Make grep search all folders?

I have code that will grep through all files in a cpanel but am unsure what arguments to use in the shell command.

Currently this is the line of code going into shell_exec(): $command = "grep -il '.$term.' ./*";

This is only searching the files in the folder that this script is in. Adding the -r argument does not fix it nor does -d recursive.

Upvotes: 0

Views: 163

Answers (2)

kstenger
kstenger

Reputation: 374

grep -r "some string" <dir>

This will recursively search all directories below dir

Hope it helps.

Upvotes: 0

KevinDTimm
KevinDTimm

Reputation: 14376

find . -exec grep -il '.$term.' {} \;

The '\' may be unnecessary on windows machines but will be necessary on *nix

Upvotes: 2

Related Questions