Spencer Rohan
Spencer Rohan

Reputation: 1939

How to open google chrome from terminal?

I'm trying to create an alias that opens google chrome to localhost. Port 80 in this case.

I'd also really like to be able to be in any git directory and have it open that specific project in the browser, but I'm not sure if that's even possible.

More Details:

  1. My localhost is set to port 80.
  2. I store my git repositories in ~/Sites/ - meaning if I wanted to view any project in the browser it would be found here: http://localhost/FILENAME

Thank You

Upvotes: 116

Views: 256856

Answers (11)

Rohim Chou
Rohim Chou

Reputation: 1269

For Windows:

start chrome "https://www.google.com"

Upvotes: 4

аlex
аlex

Reputation: 5698

For macOS you can use this command:

open -a Google\ Chrome "https://google.com"

Upvotes: 11

Paweł Witek
Paweł Witek

Reputation: 181

On linux [ubuntu] in terminal, write:

google-chrome 'https://google.com' 2> /dev/null

ending part 2> /dev/null ommits output from command in terminal and allows to type without disturbing comments from that command.

for new-ones in scripting (linux users):
u can also create some nice readable function in ~/.bashrc directory like:

open(){
    google-chrome $1 2> /dev/null
}

and in terminal using it like this:

open htts://google.com

Upvotes: 2

Ajay kumar
Ajay kumar

Reputation: 41

Use command

google-chrome-stable

We can also use command

google-chrome

To open terminal but in my case when I make an interrupt ctrl + c then it get closed so I would recommend to use google-chrome-stable instead of google-chrome

Upvotes: 4

MauiGonzo
MauiGonzo

Reputation: 41

on mac terminal (at least in ZSH): open stackoverflow.com (opens site in new tab in your chrome default browser)

Upvotes: 4

Y. Joy Ch. Singha
Y. Joy Ch. Singha

Reputation: 3252

just type

google-chrome

it works. Thanks.

Upvotes: 5

DGomonov
DGomonov

Reputation: 845

In Terminal, type open -a Google\ Chrome

This will open Google Chrome application without any need to manipulate directories!

Upvotes: 2

Spencer Rohan
Spencer Rohan

Reputation: 1939

UPDATE:

  1. How do I open google chrome from the terminal?

Thank you for the quick response. open http://localhost/ opened that domain in my default browser on my Mac.

  1. What alias could I use to open the current git project in the browser?

I ended up writing this alias, did the trick:

# Opens git file's localhost; ${PWD##*/} is the current directory's name
alias lcl='open "http://localhost/${PWD##*/}/"'

Thank you again!

Upvotes: 15

Miko
Miko

Reputation: 647

On Linux, just use this command in a terminal:

google-chrome

Upvotes: 49

John
John

Reputation: 1963

From the macOS Terminal, use open with the -a flag and give the name of the app you want to open. In this case "Google Chrome". You may pass it a file or URL you want it to open with.

open -a "Google Chrome" index.html 

Upvotes: 154

theRana
theRana

Reputation: 704

If you just want to open the Google Chrome from terminal instantly for once then open -a "Google Chrome" works fine from Mac Terminal.

If you want to use an alias to call Chrome from terminal then you need to edit the bash profile and add an alias on ~/.bash_profile or ~/.zshrc file.The steps are below :

  • Edit ~/.bash_profile or ~/.zshrc file and add the following line alias chrome="open -a 'Google Chrome'"
  • Save and close the file.
  • Logout and relaunch Terminal
  • Type chrome filename for opening a local file.
  • Type chrome url for opening url.

Upvotes: 32

Related Questions