Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

find

shell

unix

People also ask

How do I search for all files with specific extensions?

For finding a specific file type, simply use the 'type:' command, followed by the file extension. For example, you can find . docx files by searching 'type: . docx'.

Which command is used to list all the files with extension txt?

Long format with file size: ls -ls. List only the . txt files in a directory: ls *. txt.


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

find /path/to/  \( -iname '*.gif' -o -iname '*.jpg' \) -print0

will work. There might be a more elegant way.


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

The -E saves you from having to escape the parens and pipes in your regex.


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/

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

On Mac OS use

find -E packages  -regex ".*\.(jpg|gif|png|jpeg)"

In supplement to @Dennis Williamson 's response above, if you want the same regex to be case-insensitive to the file extensions, use -iregex :

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