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

How to find all files with a specific extension list

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

find /Users/david/Desktop/-type f 

如何才能只找到扩展名为 txt mpgjpg 的文件?

这是一个荒谬且非常低级的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

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

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