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

I'm using OpenBox window manager without any desktop enviroment.

xdg-open behaves strangely. It opens everything with firefox.

$ xdg-settings --list
Known properties:
  default-web-browser           Default web browser

I'm looking for simple program. Someting like reading every *.desktop file in /usr/share/applications/ folder and automatically setting xdg settings.

share|improve this question
using xdg-mime (part of xdg-utils) is the best answer for working with (querying, configuring) xdg-open. See also unix.stackexchange.com/questions/8793/… – michael_n Jan 2 '14 at 9:01
up vote 15 down vote accepted

You can use perl-file-mimeinfo in the extra repository to manage mimetypes.

Example to open all .pdf files in apvlv:

/usr/bin/vendor_perl/mimeopen -d $file.pdf

and then, at the prompt, enter the application: apvlv.

share|improve this answer
It work's. But it only opens file. So my xdg-open left unconfigured and applications using xdg-open won't open files right. – kravemir Apr 15 '12 at 8:53
I don't quite follow your comment. What is not working? The -d switch sets the default. So if you use it to open fileA.pdf - you should then be able to open fileB.pdf with your preferred application. – jasonwryan Apr 15 '12 at 9:34
Yes. mimeopen -d a.pdf sets default for *.pdf, but it sets default for itself - mimeopen b.pdf works. But xdg-open configuration left unchanged and it still opens everything with firefox :/ – kravemir Apr 19 '12 at 12:40
Once I have set the default with mimeopen, xdg-open behaves as expected--in the case of .pdfs, it opens them with apvlv. – jasonwryan Apr 20 '12 at 7:50
Yep, thanks. It's now working. I don't know why it didn't work before. I did same. – kravemir Apr 20 '12 at 16:00

Why not to use utilities from xdg itself?

To make Thunar the default file-browser, i.e. the default application for opening folders.

$ xdg-mime default Thunar.desktop inode/directory

to use xpdf as the default PDF viewer:

$ xdg-mime default xpdf.desktop application/pdf

This should create an entry in your local MIME database:

[Default Applications]

Your PDF files should be opened with xpdf now.

share|improve this answer
+1 and see also my related answer to the related question, unix.stackexchange.com/questions/77136/… – michael_n Jan 2 '14 at 8:57
Most useful answer, thanks. Easiest to know about defaults.list so it can simply be edited by hand if need be. – mVChr May 24 at 21:08
For some reason xdg-mime did not modify defaults.list, but editing it manually (thanks to hints in this answer) did the trick. – Skippy le Grand Gourou Jun 28 at 12:45
FYI few Perl dependencies are required for this, make sure you have them installed. RPM/DEB distributions will install these for you normally. – lzap Jul 13 at 6:56

On Debian you could use the command, as root

update-mime-database /usr/share/mime

having the shared-mime-info package installed.

share|improve this answer
I've tried it. It doesn't work. I'm running Arch. – kravemir Apr 14 '12 at 12:44

You could use something like this to generate the appropriate xdg-mime commands for each of your .desktop files and the mimetypes they contain, then execute the ones you like. Note /usr/share/applications might have subdirectories.

for dd in /usr/share/applications ~/.local/share/applications; do
  for d in $(ls $dd 2>/dev/null | grep "\\.desktop$"); do
    for m in $(grep MimeType $dd/$d | cut -d= -f2 | tr ";" " "); do
      echo xdg-mime default $d $m;
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.