linux

Getting a file's MIME type

1 min read

Has a file ever seemed to be in a certain format, but the application you use can’t handle it?

This can happen, for example, when the file extension is wrong. How can we find out what type of file we have?

To get the MIME type of a file, and so work out which application can handle it, we can use the file command.

We can use the command like this:

bash
file --mime-type filename.ext

This gives us the file’s MIME type. If we only want the file’s encoding, we can use –mime-encoding instead of –mime-type.

bash
file --mime-encoding filename.ext

We can also get both pieces of information with the -i option:

bash
file -i filename.ext

#linux