Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I recently switched to gnome3 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? Thanks in advance :)

share|improve this question

2 Answers 2

up vote 0 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
1  
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:

...
MimeType=text/plain;text/wiki;text/foo;
...

They should then be automatically launched on these files.

share|improve this answer

Your Answer

 
discard

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.