How to get a file's UTI from the command line in Mac OS X?

You can use the mdls command to find the UTI for a file:

mdls /Library/Desktop\ Pictures/Aqua\ Blue.jpg

and it will give you a bunch of info, toward the top it will say something like

kMDItemContentType             = "public.plain-text"

Hope this helps!


The mdls command only seems to work on Spotlight indexed files. If you run it on a mounted disk image, cd or thumb drive it may return no information at all.

When you're developing a Quicklook Plugin it's also useful to use the following command to see what UTIs Quicklook thinks a file has and which plugins it uses for the preview:

qlmanage -d 4 -p /path/to/file