I ask this question for running an find command.

I want to list all mp3(lets say) using the find command.How to do this without having an extension.

link|improve this question

80% accept rate
feedback

1 Answer

up vote 2 down vote accepted

This will do it for almost all audio files. Strangely it missed some here because they were of type "application/octet-stream". Maybe they are badly encoded.

find -type f -exec file --mime-type '{}' \+ | grep "audio/mpeg"

or without mimetype in the list

find -type f -exec file --mime-type '{}' \+ | grep "audio/mpeg" | sed 's;:\s*audio/mpeg$;;'

link|improve this answer
1  
I suggest + in lieu of \; and \s* in lieu of the space between : and audio. – enzotib Jul 6 '11 at 14:24
Great. But I was looking for a more general solution, which would work for other types, like pictures or videos.Can it be extened? – Mad-scientist Jul 6 '11 at 14:46
This command can give a hint of the mime type to use for a given extension, say mp3: awk '/mp3/ { print $1 }' /etc/mime.types – enzotib Jul 6 '11 at 15:11
Mad-scientist: every file has a type. file <file> is the best way to determine a file's type. Returning a MIME type is only one possibility. Read man file for further information. – dAnjou Jul 6 '11 at 21:57
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.