How to use find command to find all files with extensions from list?

后端 未结 9 1538
旧时难觅i
旧时难觅i 2020-12-04 05:45

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 f

9条回答
  •  囚心锁ツ
    2020-12-04 06:25

    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/
    

提交回复
热议问题