6

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.)

7

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

1
  • Thx that did the trick Nov 29 '12 at 18:33
0

(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:

/usr/share/applications/firefox.desktop
/usr/share/xfce4/helpers/firefox.desktop

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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