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;

“修剪”目录中的文件被省略:

./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这是忽略和查找程序在“修剪”目录中搜索的唯一原因吗?

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);

请注意,-printand-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 回答