Skip to main content
removed unnecessary glob and the -r from find grep.
Source Link
Gregg Leventhal
  • 7.8k
  • 19
  • 70
  • 105

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can at least do some filtering if you know the file extension or a regex that matches the file name, but when you only know -type f which is better? GNU grep 2.6.3; find (GNU findutils) 4.4.2

Example:

grep -r -i 'the brown dog' /*

find / -type f -exec grep -i -r 'the brown dog' {} \;

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can at least do some filtering if you know the file extension or a regex that matches the file name, but when you only know -type f which is better? GNU grep 2.6.3; find (GNU findutils) 4.4.2

Example:

grep -r -i 'the brown dog' /*

find / -type f -exec grep -i -r 'the brown dog' {} \;

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can at least do some filtering if you know the file extension or a regex that matches the file name, but when you only know -type f which is better? GNU grep 2.6.3; find (GNU findutils) 4.4.2

Example:

grep -r -i 'the brown dog' /

find / -type f -exec grep -i 'the brown dog' {} \;

Source Link
Gregg Leventhal
  • 7.8k
  • 19
  • 70
  • 105

Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can at least do some filtering if you know the file extension or a regex that matches the file name, but when you only know -type f which is better? GNU grep 2.6.3; find (GNU findutils) 4.4.2

Example:

grep -r -i 'the brown dog' /*

find / -type f -exec grep -i -r 'the brown dog' {} \;