为什么我需要在 linux find 命令中'-o'?



我想列出某些目录下具有特定名称模式的文件,不包括某些子目录。通过

find "../../" -path "../../backup" -prune -regex ".*.v" -print

不输出任何内容。但是通过添加-o

find "../../" -path "../../backup" -prune -o -regex ".*.v" -print

我得到正确的结果。-o表示or。但是我认为我的要求中没有or逻辑,我认为应该是and?

file name with certain pattern & under certain directory & not under certain sub-directory

我做错了什么吗?

find手册页:

-prune True;  if the file is a directory, do not descend into it.  
If -depth is given, false; no effect.  
expr1 -o expr2
Or; expr2 is not evaluated if expr1 is true.
The construct -prune -o ( ... -print0 ) is quite common.  
The idea here is that the  expression before -prune matches 
things which are to be pruned.
However, the -prune action itself returns true, so the following 
-o ensures that the right hand side is evaluated only for 
those directories which didn't get pruned (the contents of 
the pruned directories are not even visited, so their contents are irrelevant).

最新更新