I was wondering what's the terminal command to open the default web browser.
7 Answers
xdg-open <URL> is the command you're looking for.
Or:
sensible-browser but as per sensible-browser(1), it only works properly on Debian or if the BROWSER environment variable is set. There’s also an open but stale MR in the sensible-utils repository to respect Ubuntu’s xdg-settings.
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.
You can also use:
x-www-browser http://some-url.org
And it will open the URL in the default browser.
- 4,780
Just that you may find it useful. A fallback approach, and a one-liner:
URL="https://www.url.com/some"; xdg-open $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URL
You can also add the following function to your system (your shell script, .bashrc, .zshrc, alias or functions files, ...):
function openUrl() {
local URL="$1";
xdg-open $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URL;
}
and you use as:
openUrl www.wikipedia.com
Good reading for the no familiar with the logical operators https://www.howtogeek.com/269509/how-to-run-two-or-more-terminal-commands-at-once-in-linux/.
; => run in all cases,
|| => run if the precedent command failed (or)
&& => run only if the precedent command succeed
and
var=someval -> set a variable
$var -> invoke the variable
- 203
With default Ubuntu setup only gnome-open command comes to mind.
gnome-open http://askubuntu.com
- 1,616
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=https://your.website —kiosk &
- 121
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). )
- 61,858