[英]Exclude hidden files and folders in linux find
I am trying to exclude hidden files and folders when doing a find
in linux.在 linux 中进行
find
时,我试图排除隐藏文件和文件夹。
I have to exclude files or folders that start with a dot (.hidden) but also have to exclude folders that start with an @ (like @eaDir).我必须排除以点 (.hidden) 开头的文件或文件夹,但也必须排除以 @ 开头的文件夹(如 @eaDir)。
So far I have the following command which seems to work but maybe there is a more elegant way?到目前为止,我有以下命令似乎有效,但也许有更优雅的方式?
find /path/to/start/search/ -not -path '*@eaDir*' -not -path "*/\.*" -type f -mtime -2
I did see examples using regular expression like so:我确实看到了使用正则表达式的示例,如下所示:
find . \( ! -regex '.*/\..*' \) -type f
but not sure how I would also exclude @eaDir
directories with the -regex
option?但不确定如何使用
-regex
选项排除@eaDir
目录?
I believe there can also be hidden files that start with two dots?我相信也可以有以两个点开头的隐藏文件? like "..hidden"?
像“..隐藏”? Is this already covered with my command or would I simply add a third option like
-not -path "*/\..*"
to exclude those as well?这是否已经包含在我的命令中,还是我会简单地添加第三个选项,例如
-not -path "*/\..*"
来排除这些选项?
Then I saw some examples of using -prune
so that find won't descend in hidden directories, however I am unsure how I would use this correclty in my example.然后我看到了一些使用
-prune
的示例,以便 find 不会下降到隐藏目录中,但是我不确定如何在我的示例中使用这个 correclty。 I would be interested in this to speed things up.我会对此感兴趣以加快速度。
Thanks!谢谢!
Use -not -name '.*'
.使用
-not -name '.*'
。 This will exclude any names that begin with .
这将排除任何以 . 开头的名称
.
. .
Exclude files and folders starting with a .
排除以
.
or an @
:或
@
:
find /path/to/start/search/ -not -path '*/[@.]*' -type f -mtime -2
Exclude files starting with a .
排除以
.
and files and folders starting with a .
以及以 . 开头的文件和文件夹
.
or an @
:或
@
:
find /path/to/start/search/ -not -path '*/.*' -type f -mtime -2 | grep -v '/@.*/.*'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.