Get the mime-type of a file
The file command for both Linux and Mac can provide mime information with the -I flag.
> file -I cool_song.aif
cool_song.aif: audio/x-aiff; charset=binary
There are longer flags to limit this information, --mime-type and --mime-encoding.
> file --mime-type cool_song.aif
cool_song.aif: audio/x-aiff
> file --mime-type cool_song.aif
cool_song.aif: binary
And if you are using this information in a script you can remove the prepended file name with the -b flag.
> file --mime-type -b cool_song.aif
audio/x-aiff
> file --mime-type -b cool_song.aif
binary
Combine -b and -I for a quick terse mime information command
> file -bI cool_song.aif
audio/x-aiff; charset=binary
Tweet