0

I wish to use a grep search to find the string 'base64' in any/all php files in a folder (and its subfolders) saved on my mac's desktop. I'm not very experienced using the Terminal command line functions. I've written

grep -lr base64  *.php

but this only finds the relevant php files in the folder, not its subfolders. What is the correct command to show every php file I'm looking for?

terdon
  • 52,568
  • 14
  • 124
  • 170
  • 5
    Possible duplicate of [How can I "grep" recursively filtering the name of the files I want with wildcards?](http://superuser.com/questions/757834/how-can-i-grep-recursively-filtering-the-name-of-the-files-i-want-with-wildcar) – user193661 Oct 03 '15 at 11:52

2 Answers2

2

You could use the --include option of grep

grep -lr base64 --include=*.php
F. Pareto
  • 121
  • 2
-1

Yup. Thanks @Clearquestionwithexamples

find . -iname "*.php" -exec grep -Hi base64 {} \;

That seems to be the answer to what you're looking for (search for "base64" in *.php files), and is based on some of the available answers in referenced resources.

If you have a directory that just has *.php files, you can use this even-easier syntax:

grep -iR base64

To just “show every php file I'm looking for” (and not bother with looking for “base64”), you can do that with simply:

find . -iname "*.php"
TOOGAM
  • 15,243
  • 4
  • 41
  • 58