Yeah, I belatedly realized that that may have been his desire, which is why I went pack to edit my post. In either case my point on the correct use of
find is the same.
To add a bit of further clarification, "
|" pipes send the stdout of the first command, that is, the text that usually prints on screen, into the stdin of the second command. How that command handles the input depends on it's design, but most text editing commands like
grep just process it as-is, as
text. Only a small number of commands such as
xargs actually read them as filenames (and find's
-exec option can usually replace
xargs).
Another way to process a list of filenames is to use a shell
while loop, particularly if you need to do complex operations on them :
Code:
while IFS='' read -r -d '' fname; do
grep 'string' "$fname"
done < <( find. -type f -mtime -1 -print0 )
You should always use null separators (-print0) when the exact input patterns are unknown.
If the file matching depends only on name patterns, and not mtime or such, then you can also just use
grep's built-in recursive file processing.
Code:
grep -r --include='*.txt' -e '^I' ./
This will search all textfiles for the given pattern.
All this is covered in the links I gave above.