What’s that file then? How to identify unknown file types

Autumn/fall must be spring cleaning time on Macs, in preparation for upgrading macOS. With all sorts of issues over 32-bit app loss and old QuickTime encodings, this year will probably see more thorough rummaging through long-forgotten documents. And some of them will prove mysteries: what type of document is that?

If the file in question has an extension, then it shouldn’t be so hard to work out what type of document it should be. Only sometimes those extensions don’t ring a bell, or look quite inappropriate in the Finder. One useful tool here is my free UTIutility: simply type in the extension without the leading period/stop and it asks macOS which file type is recognised.

utiutil19

But even that can prove misleading, as some extensions are used for more than one type of file. macOS may be as puzzled as you are, in which case it will give you a ‘dynamic’ UTI something like dyn.age8xnrv1, which is of no use.

So where can you turn next? The answer is some magic, and the file command in Terminal. This is an amazingly valuable command which every Mac user should be familiar with. file uses a series of three different tests to try to discover what type of file it is dealing with:

  1. the file system, from which it discovers what macOS knows about the file,
  2. the magic test, in which it looks at signature bytes at the start of the file,
  3. various text file encodings.

It returns the first result it obtains by applying those in that order.

Type in a command like
file unknownfiletype
and it might respond something like
unknownfiletype: Rich Text Format data, version 1, unknown character set

For the more advanced user, file has more tricks up its sleeve. Its man page is exemplary, and full of additional detail about those, and more.

If you want to use these ‘magic numbers’ yourself, man magic explains the database which file uses, which can be found in /usr/share/file. There’s a helpful compilation on Wikipedia, and Gary Kessler maintains an excellent listing here.