7

I'm trying to find out all of the different types of files in my unorganized music folder. I've been trying this command (to list files of types besides the ones I know are in there):

find zUnorganized/ -not -iname "*.mp3" -and -not -iname "*.flac" -and -not -iname "*.MP3" -and -not -iname "*.wav" -or -not -iname "*.m4a" -and -not -iname "*.jpg"

But it's not working. How would I get that command work? Is there a way to do it using -regex?

Thanks!

1
  • As the title asks explicitly for "file type", not file name extension or so: To find the file type based on what is actually contained in the file, use the command file. Commented Apr 17, 2014 at 8:09

1 Answer 1

7

You wrote (redundant parentheses added for clarity):

find zUnorganized/ \( -not -iname "*.mp3" -and -not -iname "*.flac" -and -not -iname "*.MP3" -and -not -iname "*.wav" \) \
               -or \( -not -iname "*.m4a" -and -not -iname "*.jpg" \)

Either use -and -not throughout, or use or throughout and finish with -print (meaning: do nothing for this, otherwise do nothing for that, etc, otherwise print). You'll also want to limit the search to regular files, otherwise directories will be listed.

find zUnorganized/ -type f -not -iname "*.mp3" -and -not -iname "*.flac" -and -not -iname "*.MP3" -and -not -iname "*.wav" -and -not -iname "*.m4a" -and -not -iname "*.jpg"
find zUnorganized/ \! -type f -o \
                   -iname "*.mp3" -o -iname "*.flac" -o -iname "*.MP3" -o -iname "*.wav" -o -iname "*.m4a" -o -iname "*.jpg" -o \
                   -print
2
  • just to clarify how the second command you wrote works, it means find files in zUnorganized that are NOT files or that have these types and do nothing, otherwise print? Commented Feb 1, 2011 at 20:27
  • 1
    It evaluates left-to-right, and short-circuit evaluation means it only bothers to evaluate -print if all the preceding tests are false. Commented Feb 1, 2011 at 21:33

You must log in to answer this question.