2015-09-18 27 views

回答

3

您可以使用-ofind過濾器,以不同的標準與 「OR」 相結合。您需要將它們放在括號中,因爲它們的優先級低於默認的「AND」條件組合。

find /Users/david/Desktop -type f \(-name '*.txt' -o -name '*.mpg' -o -name '*.jpg' \) 
+0

謝謝,有沒有辦法讓它不區分大小寫? – David542

+0

使用'-iname'而不是'-name' – Barmar

+0

謝謝你的作品 – David542

0

這是一個荒謬的和非常低的水平bash的方式做到這一點:

複製和粘貼:

mkfifo /tmp/grep1 
mkfifo /tmp/grep2 
grep -i "dmg" /tmp/grep1 & export GREP1=$! 
grep -i "zip" /tmp/grep2 & export GREP2=$! 
find ./ -type f | tee /tmp/grep1 /tmp/grep2 >/dev/null 
echo $GREP1 
echo $GREP2 
kill $GREP1 
kill $GREP2 
rm -f /tmp/finder 
ps -a | grep -i grep 

我遭受證明這是可行的。

輸出示例:

bash-3.2$ mkfifo /tmp/grep1 ; mkfifo /tmp/grep2 ; grep -i "dmg" /tmp/grep1 & export GREP1=$! ; grep -i "zip" /tmp/grep2 & export GREP2=$! ; find ./ -type f | tee /tmp/grep1 /tmp/grep2 >/dev/null ; echo $GREP1; echo $GREP2 ; kill $GREP1 ; kill $GREP2 ; rm -f /tmp/finder ; ps -a | grep -i grep 
mkfifo: /tmp/grep1: File exists 
mkfifo: /tmp/grep2: File exists 
[6] 82891 
[7] 82892 
.//iTerm2-2_1_1.zip 
.//Cisco_WebEx_Add-On.dmg 
.//MacPass-0.5.1-alpha.zip 
.//googlechrome-2.dmg 
.//googlechrome.dmg 
82891 
82892 
bash: kill: (82891) - No such process 
[6]- Done     grep -i "dmg" /tmp/grep1 
[7]+ Done     grep -i "zip" /tmp/grep2 
82897 ttys012 0:00.00 grep -i grep 
+0

一個空間,將擴大通配符'* .mpg'成文件名的列表,所以它會執行'grep的-i file1.mpg file2.mpg file3.mpg。 ..' – Barmar

+0

這是如何回答他關於如何搜索多個擴展的問題? – Barmar

+0

我不好,我會更好地編輯。 –

相關問題