Shell &引用;查找“;带有/不带-a的实用程序和多个表达式

Shell &引用;查找“;带有/不带-a的实用程序和多个表达式,shell,unix,Shell,Unix,两者之间有什么区别吗 find . ! -name name1 ! -name name2 及 在什么情况下我应该使用“-a”?没有区别-ist是and的缩写,当您不提供它时,它是默认值(其他可能的非一元运算符是“或”和“,”)。正如find手册页所述,除非您特别说明,否则所有的原色都隐式地为“and”。因此,这两个命令实际上是等效的 相关POSIX报价: 表达式[-a]表达式 Conjunction of primaries; the AND operator is implied by t

两者之间有什么区别吗

find . ! -name name1 ! -name name2


在什么情况下我应该使用“-a”?

没有区别-ist是and的缩写,当您不提供它时,它是默认值(其他可能的非一元运算符是“或”和“,”)。

正如
find
手册页所述,除非您特别说明,否则所有的原色都隐式地为“and”。因此,这两个命令实际上是等效的

相关POSIX报价:

表达式[-a]表达式

Conjunction of primaries; the AND operator is implied by the
juxtaposition of two primaries or made explicit by the optional -a
operator. The second expression shall not be evaluated if the first
expression is false.

因此,您不需要
-a
,但对于较大的表达式,它可能更具可读性。

吹毛求疵:
-和
-或
都不是标准(POSIX)选项。这些都是GNUISM。如果可能的话,坚持使用POSIX总是一个好主意,尤其是在回答OP没有指定任何特定操作系统的问题时。阅读所有关于POSIX
find
here:Jens:即使在我使用的其他系统(AIX、HPUX、Solaris等)上,我们也安装了所有UTIL的gnu版本(grep、awk、find等)——我有时会忘记它。你完全正确。
Conjunction of primaries; the AND operator is implied by the
juxtaposition of two primaries or made explicit by the optional -a
operator. The second expression shall not be evaluated if the first
expression is false.