Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Is there a linux API that can find the default application for a MIME type? Then I can use this application to open a file.

I can not use xdg-open(url) because the file format is a wrapper format and shared mime-type can only tell the wrapper MIME type. The embedded mime type can only be got from the wrapper file header.

The process would be like: 1. find embedded mime type 2. mime-open(embedded mime type, url)

Is it possible?

share|improve this question
up vote 8 down vote accepted

The xdg-mime command is used to query or set file associations.

jinx:735 Z$ xdg-mime query default application/pdf  
share|improve this answer
This is a good answer, because this program is specifically designed to work across popular desktop environments (KDE, Gnome, others). It's part of a set of related tools called "Portland", a.k.a. xdg-utils, from portland.freedesktop.org/wiki. – mattdm Mar 8 '11 at 3:24
Also note that it's a (long) shell script, so if you want to find out how to get the information for a specific desktop environment, you can read it to find out. – mattdm Mar 8 '11 at 3:26

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.