I think xdg-open
is the command you are looking for.
NAME
xdg-open - opens a file or URL in the user's preferred application
SYNOPSIS
xdg-open {file | URL}
xdg-open {--help | --manual | --version}
DESCRIPTION
xdg-open opens a file or URL in the user's preferred application. If a
URL is provided the URL will be opened in the user's preferred web
browser. If a file is provided the file will be opened in the preferred
application for files of that type. xdg-open supports file, ftp, http
and https URLs.
eg: xdg-open index.php
This will open index.php in gedit(if you are using gnome).
If you want to open a url in browser
xdg-open http://google.com
this will open google.com in your default browser.
xdg-open
is a wrapper script - it will use the desktop environment's tool (gio open
, gvfs-open
, kde-open
, gnome-open
, dde-open
, exo-open
, and a host of other such tools). It is also installed by default, and very likely to work on past, current and future versions (on the other hand, gvfs-open
and gnome-open
have been deprecated, and may be unavailable in future releases).
I ran into this problem running konsole in Ubuntu/Unity. When everything else failed, I edited ~/.kde/share/config/kdeglobals
:
[General]
BrowserApplication[$e]=!google-chrome
Logout, login -- bingo!
Best Answer
Programs use a variety of other programs to determine the default browser -
sensible-browser
&xdg-open
being two of them.For
xdg-open
, you can use it simply by by runningxdg-open http://URL
, soxdg-open https://www.google.co.uk
will open Google for instance.This should be the same as running
echo https://www.google.co.uk
in terminal and clicking on the link should open the default browser (in my case, Firefox).You can see what is the default browser using
xdg-settings get default-web-browser
:To set values, you do
xdg-settings set default-web-browser LAUNCHER-FILE.desktop
:So now running
echo https://www.google.co.uk
and clicking on the link or runningxdg-open https://www.google.co.uk
should open Google in the new default browser (in my case now Chromium).Notice that it links to the program's .desktop file not it's command - this needs to be a valid file in
/usr/share/applications
(or~/.local/share/applications
). You can easily create your own with a custom command easily by copying a existing one and changing the 'Name' and 'Exec' lines:In the above I created a new launcher, edited it so it would launch a new window of Firefox, and updated the database of launcher files and set it to default. Now running
xdg-open https://www.google.co.uk
opens a new window of Firefox.More info:
xdg-open
without any enviroment? - Unix & Linux