5

Is there a way to open Chrome (or other browser) using terminal?

Something like: $ chrome www.google.com ?

  • 1
    Do you want to open it to a specific web page or just open the browser? – TheWanderer Oct 7 '15 at 11:57
10

From: Terminal command to open URL's in default and non-default browser (which I don't think is a duplicate)

If you want to open Chrome to a specific URL, just run

google-chrome www.example.com

To open your default browser to a specific URL, run

xdg-open www.example.com  

If you need to run Chrome and close the terminal window afterward, run

google-chrome http://www.google.com </dev/null >/dev/null 2>&1 & disown

>/dev/null 2>&1 will prevent messages from the browser to be outputted to the terminal's window; & will put the process into the background and disown will remove the job / process from the job list, preventing a SIGHUP signal to be propagated to it.

To do this with another browser simply replace google-chrome with that other browser's executable name.

  • Thanks! But there is a slight difference comparing to using a launcher. I will kill the process if I close terminal or ctrl+c. It's not a big deal though. – zombie_ghast Oct 7 '15 at 12:15
  • @kos is it alright if I add this to my answer? – TheWanderer Oct 7 '15 at 12:48
  • Sure, but use google-chrome http://www.google.com </dev/null >/dev/null 2>&1 & disown, because stdout and stderr get printed to the terminal without the redirections – kos Oct 7 '15 at 12:59
  • @kos Is it correct? – TheWanderer Oct 7 '15 at 13:13
  • Almost: >/dev/null 2>&1 prevents stdout and stderr to be printed to the terminal, </dev/null "closes" stdin, but to be honest that's not really necessary; & puts the process into the background and disown removes the process from the bash instance's jobs list, which prevents the SIGHUP signal sent to bash instance upon the terminal closure to be propagated to it – kos Oct 7 '15 at 13:42
4

You can open Google Chrome from terminal very surprisingly by running

google-chrome

You can also start Firefox by running

firefox

And you can add an URL as a parameter to open it too.

firefox www.askubuntu.com
  • Awesome! But there is a slight difference comparing to using a launcher. I will kill the process if I close terminal or ctrl+c. It's not a big deal though. – zombie_ghast Oct 7 '15 at 12:14
  • once I refreshed page a bit of your answer was gone, but I think it's useful to keep it: nohup google-chrome & – zombie_ghast Oct 7 '15 at 12:57
  • That does not work. It still closes Chrome. You may need to use screen. – Pilot6 Oct 7 '15 at 13:10
2

sensible-browser seems to be the option you're looking for. This will run the web browser set as default on your system, you can also pass parameters on it in order to run the web browser and open the given website(s).

Usage:

In a terminal, drop the next and hit Return

sensible-browser

Passing parameters:

The next command will open youtube.com in your preferred web browser:

sensible-browser youtube.com

How to set my favorite web browser flavour from the terminal?

Simply drop the next command in a terminal, hit Return and choose wisely:

sudo update-alternatives --config x-www-browser

In the next example I am choosing luakit as my default browser. You can change your default web browser as many times as you wish.

geppettvs@T400:~$ sudo update-alternatives --config x-www-browser
There are 5 choices for the alternative x-www-browser (providing /usr/bin/x-www-browser).

  Selection    Path                           Priority   Status
------------------------------------------------------------
* 0            /usr/bin/google-chrome-stable   200       auto mode
  1            /usr/bin/firefox                40        manual mode
  2            /usr/bin/google-chrome-stable   200       manual mode
  3            /usr/bin/konqueror              30        manual mode
  4            /usr/bin/luakit                 10        manual mode
  5            /usr/bin/xlinks2                69        manual mode

Press enter to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/luakit to provide /usr/bin/x-www-browser (x-www-browser) in manual mode

Unattaching from terminal

If you wish to keep your web browser running just after you close your terminal, simply add an ampersand symbol at the end of your command:

sensible-browser [parameters] &

Good luck!

  • 1
    Nice, but without disown closing the terminal SIGHUPs it; you want to add disown and to redirect at least stdout and stderr to avoid messages to be still outputted to the terminal (and maybe stdin for "formal correctness"): sensible-browser [parameters] </dev/null >/dev/null 2>&1 & disown – kos Oct 7 '15 at 13:05

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