How to launch default web browser from the terminal?
I was wondering what's the terminal command to open the default web browser.
07 Answers
sensible-browser is the command you're looking for.
Or:
xdg-open <URL>.
Searching on Google I found the answer.
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.
xdg-open is part of xdg-utils package and it's already installed on Ubuntu 10.10.
7You can also use:
x-www-browser And it will open the URL in the default browser.
2Just that you may find it useful. A fallback approach, and one liner.
URL=""; xdg-open $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URLGood reading for the no familiar with the logical operators .
; => run in all cases,
|| => run if the precedent command failed (or)
&& => run only if the precedent command succeed
and
3var=someval -> set a variable
$var -> invoke the variable
With default Ubuntu setup only gnome-open command comes to mind.
gnome-open 6 I played around this a little.
There is a problem with gnome-open — it won't invoke the default web browser unless you specify a url.
That's a problem if you want to set up an icon or a shortcut that will always launch the browser that is set as default.
Other times you might need to set it as a parameter for some programs that require a link to a web browser and don't work well with gnome-open (e.g.: acroread).
You might solve this by using either x-www-browser or gnome-www-browser system links that you can set up through update-alternatives, but those are system wide settings, not user specific (and they are not synchronized with the values set through gnome-default-applications-properties.
All this can be solved by opening the sensible-browserexecutable (which is actually a script):
sudo gedit $(which sensible-browser)and adding this at the beginning:
#!/bin/bash
BROWSER=$(gconftool -g /desktop/gnome/url-handlers/http/command)
export BROWSER="${BROWSER//"\"%s\""/}"That will make sensible-browser always launch the user-specified default web browser.
(I found out that gnome-default-applications-properties changes some gconf keys according to the browser that is currently set. The default browser value can be obtained from any of these keys so I went for /desktop/gnome/url-handlers/http/command and used it to fill the $BROWSER variable (the value is stripped of the "%s" part). )
On Raspberry Pi Ubuntu I did this to start a webpage, fullscreen (in Kiosk mode) on startup:
# put in ~/.bash_profile
DISPLAY=:0 chromium-browser --app= —kiosk &