Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
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! :) – Phani Kumar Feb 12 '12 at 14:29
Technically Nautilus uses the Shared MIME-info Database to determine the MIME type of a file. – Florian Diesch Feb 12 '12 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.