如何grep隐藏文件? [英] How can I grep hidden files?
问题描述
我正在搜索 Git 存储库并希望包含 .git
文件夹.
I am searching through a Git repository and would like to include the .git
folder.
grep
如果我运行,则不包含此文件夹
grep
does not include this folder if I run
grep -r search *
包含此文件夹的 grep 命令是什么?
What would be a grep command to include this folder?
推荐答案
请参阅本文末尾的解决方案,作为您正在做的事情的更好替代方案.
您可以显式包含隐藏文件(目录也是文件).
You can explicitly include hidden files (a directory is also a file).
grep -r search * .[^.]*
*
将匹配除隐藏文件之外的所有文件,.[^.]*
将仅匹配没有 ..
的隐藏文件.但是,如果给定目录中没有非隐藏文件或没有隐藏文件,这将失败.您当然可以显式添加 .git
而不是 .*
.
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.
这篇关于如何grep隐藏文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!