Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out a file's MIME type (Content-Type)?

People also ask

What is a file's MIME type?

A multipurpose internet mail extension, or MIME type, is an internet standard that describes the contents of internet files based on their natures and formats. This cataloging helps the browser open the file with the appropriate extension or plugin.

How would you discover MIME types and subtypes?

A MIME type has two parts: a type and a subtype. They are separated by a slash (/). For example, the MIME type for Microsoft Word files is application and the subtype is msword. Together, the complete MIME type is application/msword.

Where is the MIME type stored?

All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/ . The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop.

What are the different content types of MIME?

Currently, there are ten registered types: application, audio, example, font, image, message, model, multipart, text, and video.


Use file. Examples:

> file --mime-type image.png
image.png: image/png

> file -b --mime-type image.png
image/png

> file -i FILE_NAME
image.png: image/png; charset=binary

one of the other tool (besides file) you can use is xdg-mime

eg xdg-mime query filetype <file>

if you have yum,

yum install xdg-utils.noarch

An example comparison of xdg-mime and file on a Subrip(subtitles) file

$ xdg-mime query filetype subtitles.srt
application/x-subrip

$ file --mime-type subtitles.srt
subtitles.srt: text/plain

in the above file only show it as plain text.


file version < 5 : file -i -b /path/to/file
file version >=5 : file --mime-type -b /path/to/file


Try the file command with -i option.

-i option Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say text/plain; charset=us-ascii rather than ASCII text.