简体   繁体   中英

Find Command with multiple file extensions

I'm looking through many sub directories and finding all the files ending in .JPG .jpg and .png and copying them to a separate directory, however just now its only finding .JPG

Could someone explain what i'm doing wrong?

find /root/TEST/Images -name  '*.png' -o  -name '*.jpg' -o -name '*.JPG' -exec cp -t /root/TEST/CopiedImages {} +

You have to group the -o conditions because -a , the implied AND between the last -name '*.JPG' and -exec has higher precedence :

find /root/TEST/Images \( -name  '*.png' -o  -name '*.jpg' -o -name '*.JPG' \) -exec cp -t /root/TEST/CopiedImages {} +

Grouping is done with parentheses, but they have to be escaped (or quoted) due to their special meaning is shell.

Unrelated to this, you can shorten the overall expression by combining filters for jpg and JPG with the case-insensitive -iname (as noted in comments):

find /root/TEST/Images \( -name  '*.png' -o  -iname '*.jpg' \) -exec cp -t /root/TEST/CopiedImages {} +

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM