How to launch default web browser from the terminal?

I was wondering what's the terminal command to open the default web browser.


Solution 1:

sensible-browser is the command you're looking for.

Or:

xdg-open <URL>.

Solution 2:

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.

Solution 3:

You can also use:

x-www-browser http://some-url.org

And it will open the URL in the default browser.

Solution 4:

Just that you may find it useful. A fallback approach, and one liner.

URL="https://www.url.com/some"; xdg-open $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URL

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