如何查找具有特定扩展名列表的所有文件

时间:2015-09-18 19:29:10

标签: linux unix find

我有以下find命令,它会给我所有文件:

find /Users/david/Desktop/-type f 

我如何仅查找扩展名为txt mpgjpg的文件?

2 个答案:

答案 0 :(得分:3)

您可以在-o过滤器中使用find将不同的条件与" OR"结合使用。您需要将它们包装在括号中,因为它们的优先级低于默认值" AND"标准的组合。

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

答案 1 :(得分:0)

这是一个ABSURD和非常低级别的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