How do get an html file to open in preferred application from command line on linux?

I have an xterm window open and an html file I want to do something like

open test.html

and that will start my preferred browser with the test.html file loaded.

(I'm looking for a solution that will work for any Linux desktop machine without me needing to know which browser app they have installed.)

2 Answers 2


That's OS/distribution/desktop-environment dependent, but in many places, you'll find a xdg-open command that does just that.

  • Thx that did the trick Nov 29, 2012 at 18:33

(see https://bbs.archlinux.org/viewtopic.php?pid=732285#p732285)

1.) save some webpage (via "File > Save page as"), e.g. as /tmp/somewebpage.html

2.) find out the media-type/filetype of this file:
xdg-mime query filetype /tmp/site.html (-> text/html)

2.) find the currently assigned default app for this filetype:
xdg-mime query default text/html (-> e.g.: brave.desktop)

3.) define the new default app for this filetype:
xdg-mime default firefox.desktop text/html

Look for ".desktop"-files, e.g. in:


An(other) Ubuntu/Debian(based) option (maybe this also works for html file, I currently cant verify)

update-alternatives --get-selections (to list apps and assigned command)
update-alternatives --config ... (insert an item from the list into "...", e.g.: editor)
update-alternative --all (interactively define selection for each option)

There is a gui-tool for that: GAlternatives (https://packages.debian.org/search?keywords=galternatives)

You must log in to answer this question.

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