我需要找到所有的图像文件从目录(gif, png, jpg, jpeg)。

find /path/to/ -name "*.jpg" > log

如何修改这个字符串,不仅找到。jpg文件?


当前回答

find /path -type f \( -iname "*.jpg" -o -name "*.jpeg" -o -iname "*gif" \)

其他回答

在Mac OS上使用

find -E packages  -regex ".*\.(jpg|gif|png|jpeg)"
find /path -type f \( -iname "*.jpg" -o -name "*.jpeg" -o -iname "*gif" \)

find -E /path/to -regex ".*\.(jpg|gif|png|jpeg)">日志

-E使您不必转义正则表达式中的paren和管道。

find /path/to -regex ".*\.\(jpg\|gif\|png\|jpeg\)" > log

添加-regextype posix-extended选项只在我的情况下有效:

sudo find . -regextype posix-extended -regex ".*\.(css|js|jpg|jpeg|png|ico|ttf|woff|svg)" -exec chmod 0640 {} \;