Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 5 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$;;'

share|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
add comment

Your Answer

 
discard

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

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