Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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!

share|improve this question
    
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. –  Volker Siegel Apr 17 at 8:09

1 Answer 1

up vote 5 down vote accepted

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
share|improve this answer
    
Thanks, that clears it up!! –  user4390 Feb 1 '11 at 20:21
    
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? –  user4390 Feb 1 '11 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. –  Kowh Feb 1 '11 at 21:33
    
@Kowh thanks!!! –  user4390 Feb 1 '11 at 21:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.