tags:

views:

42

answers:

5

Hello,

I need to find all image files from directory (gif, png, jpg, jpeg).

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

How to modify this string to find not only .jpg files?

Thank you.

PS: Unix

+2  A: 
 find /path/to/ -name "*.gif" -o -name "*.jpg" -o -name "*.png" -o -name "*.jpeg"

will work. There might be a more elegant way.

JoseK
A: 
dir /s *.jpg *.gif *.png *.jpeg > log

find searches the contents of files rather than the file system.

Bermo
Hm, from "man find" : GNU find searches the directory tree rooted at each given file name by evaluating the given expression from left to right
Kirzilla
Sorry, should have realised using unix not Windows from /path/to/
Bermo
A: 
find /path -type f \( -iname "*.jpg" -o -name "*.jpeg" -o -iname "*gif" \)
ghostdog74
+1  A: 
find /path/to/ -type f -print0 | xargs -0 file | grep -i image

This uses the file command to try to recognize the type of file, regardless of filename (or extension).

If /path/to or a filename contains the string image, then the above may return bogus hits. In that case, I'd suggest

cd /path/to
find . -type f -print0 | xargs -0 file --mime-type | grep -i image/
unutbu
+1  A: 
find /path/to -regex ".*\.\(jpg\|gif\|png\|jpeg\)" > log
Dennis Williamson