我正在使用 GNU 的find
.
我已將問題簡化為這個 shell 會話:
$ mkdir t
$ cd t
$ touch a
$ ln -s a b
$ find -type l
./b
$ find -type l -o -type f
./a
./b
$ find -type l -print
./b
$ find -type l -o -type f -print
./a
也許是因為我很困,但有兩件事對我來說沒有意義:
- 不是嗎
true OR false == true
?儘管匹配,但添加-o -type f
會導致find
停止匹配./b
,這是怎麼回事-type l
? - 手冊頁說這
-print
是預設表達式,那麼當未提及時列印文件,而提及時又忽略文件,這是怎麼回事呢?
使用時也會發生這種情況-printf
(我實際需要的);我想其他表達方式也會受到影響。
答案1
在
find -type l -o -type f -print
您已指定操作,因此預設值不再適用。但-printf
這裡必然是-type f
因為「and」的優先權高於「or」;你可以認為這相當於
find \( -type l \) -o \( -type f -print \)
要以相同的方式處理連結和文件,您需要將測試分組:
find \( -type l -o -type f \) -print