Prova
find /srv/www/*/htdocs/system/application/ -name "*.php" -exec grep "debug (" {} \; -print
Questo dovrebbe cercare in modo ricorsivo le cartelle sotto application per i file con .php e passali a grep .
Un'ottimizzazione su questo sarebbe eseguire:
find /srv/www/*/htdocs/system/application/ -name "*.php" -print0 | xargs -0 grep -H "debug ("
Questo utilizza xargs per passare tutti i .php file emessi da find come argomenti di un singolo grep comando;ad esempio, grep "debug (" file1 file2 file3 . L'-print0 opzione di find e -0 opzione di xargs assicurarsi che gli spazi nei nomi di file e directory siano gestiti correttamente. Il -H opzione passata a grep assicura che il nome del file venga stampato in tutte le situazioni. (Per impostazione predefinita, grep stampa il nome del file solo quando vengono passati più argomenti.)
Da man xargs:
-0
Gli elementi di input sono terminati da un carattere null invece che da uno spazio bianco, e le virgolette e la barra rovesciata non sono speciali (ogni carattere è preso alla lettera). Disabilita la stringa di fine file, che viene trattata come qualsiasi altro argomento. Utile quando gli elementi di input possono contenere spazi bianchi, virgolette o barre rovesciate. Lo GNU trova
-print0option produce un input adatto a questa modalità.
find non è nemmeno necessario per questo esempio, si può usare grep direttamente (almeno GNU grep ):
grep -RH --include='*.php' "debug (" /srv/www/*/htdocs/system/application/
e siamo arrivati a un unico fork di processo.
Opzioni:
-R, --dereference-recursive Read all files under each directory, recursively. Follow all symbolic links, unlike -r.-H, --with-filename Print the file name for each match. This is the default when there is more than one file to search.--include=GLOB Search only files whose base name matches GLOB (using wildcard matching as described under --exclude).--exclude=GLOB Skip any command-line file with a name suffix that matches the pattern GLOB, using wildcard matching; a name suffix is either the whole name, or any suffix starting after a / and before a +non-/. When searching recursively, skip any subfile whose base name matches GLOB; the base name is the part after the last /. A pattern can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character literally.