5

私が使うとき

find . -type f -path ./source/script -prune -o -print;

「プルーニングされた」./source/script ディレクトリにファイルを取得します。

...
./source/script
./source/script/myapp02.4372d2ea3388.js
./source/script/myapp02.js
./source/script/myapp02.1798d7bc34d2.js
...

しかし、私が使用するとき:

find . -path ./source/script -prune -o -type f -print;

「pruned」ディレクトリ内のファイルは省略されています。

./generate.py
./readme.txt
./source/class/myapp02/Application.js
./source/class/myapp02/Application.js:75:      
./source/class/myapp02/__init__.js
./source/class/myapp02/Application.js~
./source/class/myapp02/theme/Font.js
./source/class/myapp02/theme/Theme.js
./source/class/myapp02/theme/Decoration.js
./source/class/myapp02/theme/Color.js
./source/class/myapp02/theme/Appearance.js
./source/class/myapp02/simulation/DemoSimulation.js
./source/class/myapp02/test/DemoTest.js
./source/translation/readme.txt
./source/index.html
./source/index.html~
./source/resource/myapp02/test.png
./Manifest.json
./config.json

別の例では、次のように表示されます。

find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

私のとの唯一の違い-type dは、 が私のコードにあるということです-type f

-pruneそれが無視され、find プログラムが「整理された」ディレクトリ内を検索する唯一の理由ですか?

4

1 に答える 1

4
find . -type f -path ./source/script -prune -o -print;

と解釈されます

find . (-type f AND -path ./source/script AND -prune) OR (-print);

find . -path ./source/script -prune -o -type f -print;

と解釈されます

find . (-path ./source/script AND -prune) OR (-type f AND -print);

-printとはtrue-pruneに評価される式であることに注意してください。

したがって、true の場合(-path ./source/script AND -prune)は評価されず、呼び出されません。そして、のすべてのファイルとサブディレクトリに当てはまります(-type f AND -print)-print`(-path ./source/script AND -prune)./source/script

于 2013-05-01T19:43:04.767 に答える