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...
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.
- How do I open google chrome from the terminal?
- What alias could I use to open the current git project in the browser?
More Details:
- My localhost is set to port 80.
- I store my git repositories in ~/Sites/ - meaning if I wanted to view any project in the browser it would be found here:
Thank You
10 Answers
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
On Linux, just use this command in a terminal:
google-chrome
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_profileor~/.zshrcfile and add the following linealias chrome="open -a 'Google Chrome'" - Save and close the file.
- Logout and relaunch Terminal
- Type
chrome filenamefor opening a local file. - Type
chrome urlfor opening url.
UPDATE:
- How do I open google chrome from the terminal?
Thank you for the quick response. open opened that domain in my default browser on my Mac.
- 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 ""'
Thank you again!
just type
google-chrome
it works. Thanks.
on mac terminal (at least in ZSH): open stackoverflow.com (opens site in new tab in your chrome default browser)
In Terminal, type open -a Google\ Chrome
This will open Google Chrome application without any need to manipulate directories!
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
On linux [ubuntu] in terminal, write:
google-chrome ' 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
For macOS you can use this command:
open -a Google\ Chrome ""