How can I grep hidden files?
Please refer to the solution at the end of this post as a better alternative to what you're doing.
You can explicitly include hidden files (a directory is also a file).
grep -r search * .[^.]*
The *
will match all files except hidden ones and .[^.]*
will match only hidden files without ..
. However this will fail if there are either no non-hidden files or no hidden files in a given directory. You could of course explicitly add .git
instead of .*
.
However, if you simply want to search in a given directory, do it like this:
grep -r search .
The .
will match the current path, which will include both non-hidden and hidden files.
I just ran into this problem, and based on @bitmask's answer, here is my simple modification to avoid the problem pointed out by @sehe:
grep -r search_string * .[^.]*
Perhaps you will prefer to combine "grep" with the "find" command for a complete solution like:
find . -exec grep -Hn search {} \;
This command will search inside hidden files or directories for string "search" and list any files with a coincidence with this output format:
File path:Line number:line with coincidence
./foo/bar:42:search line
./foo/.bar:42:search line
./.foo/bar:42:search line
./.foo/.bar:42:search line