Linuxでは、「find . -name '*.c' -or -name '*.cpp'」の正確なコマンドを知りたいです。

Linuxでは、「find . -name '*.c' -or -name '*.cpp'」の正確なコマンドを知りたいです。

最近Linuxでシェルを学んでいます。質問があります。

次のコマンドを参照してください。

$ find . -name '*.c' -or -name '*.cpp'

上記のコマンドは、次のコマンドのように内部的に処理されますか?

$ find . -name '*.c' -and -print -or -name '*.cpp' -and -print

答え1

man find説明する:

   If the whole expression contains no actions other than -prune or -print,
   -print is performed on all files for which the whole expression is true.

はい。同じですが、次のように考えるのは簡単です。

find . \( -name '*.c' -or -name '*.cpp' \) -and -print

またはより簡単で、POSIXに準拠しています。

find . \( -name '*.c' -o -name '*.cpp' \) -print

答え2

デフォルトでは、これら2つのコマンドは同じ意味を持ち、同じ出力を表示します。短いルートがありますが、なぜ時間がかかるのですか?

答え3

ORおよびAND演算子はブール論理に従います。

プリミティブ A = -name '*.c', B = -name '*.cpp', C = には-print次の式があります。

最初の例: (A+B).C

2番目の例:(AC)+(BC)

彼らは単純な数学的同等性を持っています。つまり、彼らは同じです。しかし、最初のものは短く簡潔です。

関連情報