Erstens, wie andere gesagt haben, gibt es keinen Grund find, nur rekursiv zu verwenden grep:
grep -irm 1 carrot . | wc -l
Die -m 1sorgt dafür , dass grepstoppen jede Datei nach dem ersten Spiel zu suchen. Ohne sie zählen Sie nicht die Anzahl der Dateien , die enthalten, carrotsondern die Anzahl der Zeilen . Dieselbe Datei wird mehrmals gezählt, wenn sie mehrere Instanzen von enthält carrot. Von man grep:
-r, --recursive
Read all files under each directory, recursively, following
symbolic links only if they are on the command line. This is
equivalent to the -d recurse option.
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input
files. (-i is specified by POSIX.)
-m NUM, --max-count=NUM
Stop reading a file after NUM matching lines.
Wenn Sie es wirklich, wirklich mit find machen wollen, könnten Sie es tun
find . -type f -exec grep -im 1 carrot {} \; | wc -l
Beachten Sie, dass ich spezifiziere, -type fda Sie keine grepVerzeichnisse möchten .