How do I find a string contained in (possibly multiple) files in a folder including hidden files and subfolders?
I tried this command:
find . -maxdepth 1 -name "tes1t" -print0 | sed 's,\.\/,,g'
But this yielded no results.
How do I find a string contained in (possibly multiple) files in a folder including hidden files and subfolders?
I tried this command:
find . -maxdepth 1 -name "tes1t" -print0 | sed 's,\.\/,,g'
But this yielded no results.
grep -Hnr PATTERN .
if your grep supports -r
(recursive, = -d recurse
). Note there would be no limit on recursion depths then.
Or try grep -d skip -Hn PATTERN {,.[!.]}*{,/{,.[!.]}*}
; this should work since grep accepts multiple file arguments. Just throw away the -d skip
stuff if your version of grep
doesn't support it. For shells without the brace expansion, use the manually expanded form * */* */.[!.]* .[!.]* .[!.]*/* .[!.]*/.[!.]*
.
First of all, your maxdepth
should have been 2
instead of 1
, now your find command won't descend in subdirectories. Furthermore you can simply grep for your pattern on the output of find
. This can be achieved as follows:
find . -maxdepth 2 -type f -exec grep 'pattern here' '{}' \;
Explanation:
find .
execute find
in current directory.-maxdepth 2
descend in subdirectories by no further.-type f
find every file that is not a directory.-exec grep 'pattern' '{}'
execute a grep
statement with a certain pattern, the {}
contains the filename for each file found.Add options to grep for color highlighting, outputting line numbers and/or the file name.
For more information see man find
and man grep
.