I recently switched to GNOME 3 and was surprised to find that there was no way by which we could set the default applications. I am writing a Nautilus extension using Bash. I want to find the MIME type of a file.

Initially I used to extract the extension of the file using sed and build the code on it. Then I realized that there is this command called file. When I try to find the mime-type of a mkv file, the command file --mime-type -b <filename> outputs application/octet-stream but when I see the Nautilus properties window it shows the correct video/x-matroska mime-type.

Am I missing anything here? If not is there a better way in which I can file the mime-type of a file?

2 Answers 2


There are different ways to get a MIME type on Linux, and they often lead to different results. Use

xdg-mime query filetype your_file

to get the same MIME type as Nautilus gets.

  • 1
    Thanks! file command was working fine except for the mkv files.I just realized that there are two ways in which nautilus decides the file-types..the headers of a file and the extension! Lots of learning to do! :) Commented Feb 12, 2012 at 14:29
  • 1
    Technically Nautilus uses the Shared MIME-info Database to determine the MIME type of a file. Commented Feb 12, 2012 at 16:01

Look up the .desktop file of the application (i.e. gedit) in /usr/share/applications and add the MIME-Types as following:


They should then be automatically launched on these files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .