如何从终端打开 google chrome?

How to open google chrome from terminal?

我正在尝试创建一个向本地主机打开 google chrome 的别名。在本例中为端口 80。

我也非常希望能够在任何 git 目录中并让它在浏览器中打开该特定项目,但我不确定这是否可能。

更多详情:

  1. 我的本地主机设置为端口 80。
  2. 我将我的 git 存储库存储在 ~/Sites/ - 这意味着如果我想在浏览器中查看任何项目,可以在这里找到:http://localhost/FILENAME

谢谢

更新:

  1. 如何从终端打开 google chrome?

感谢您的快速回复。 open http://localhost/ 在 Mac.

的默认浏览器中打开了该域
  1. 我可以使用什么别名在浏览器中打开当前 git 项目?

我最终写了这个别名,成功了:

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

再次感谢!

在 macOS 终端中,使用 open-a 标志,并提供您要打开的应用程序的名称。在这种情况下 "Google Chrome"。您可以将文件传递给它,或者 URL 您希望它用它打开。

open -a "Google Chrome" index.html 

如果您只想从终端立即打开 Google Chrome 一次,那么 open -a "Google Chrome" 从 Mac 终端正常工作。

如果您想使用别名从终端调用 Chrome,则需要编辑 bash 配置文件并在 ~/.bash_profile~/.zshrc file.The 步骤如下:

  • 编辑 ~/.bash_profile~/.zshrc 文件并添加以下行 alias chrome="open -a 'Google Chrome'"
  • 保存并关闭文件。
  • 注销并重新启动终端
  • 键入 chrome filename 以打开本地文件。
  • 键入 chrome url 以打开 url。

在 Linux 上,只需在终端中使用此命令:

google-chrome

终端中,输入open -a Google\ Chrome

这将打开 Google Chrome 应用程序,无需操作目录!

只需输入

google-chrome

有效。谢谢

在 mac 终端上(至少在 ZSH 中):open whosebug.com(在 chrome 默认浏览器的新选项卡中打开站点)

使用命令

google-chrome-stable

我们也可以使用命令

google-chrome

打开终端,但在我的情况下,当我中断 ctrl + c 然后它关闭,所以我建议使用 google-chrome-stable 而不是 google-chrome

在linux[ubuntu]终端,写:

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

结束部分 2> /dev/null 省略终端中命令的输出,并允许在不打扰该命令注释的情况下输入。

脚本编写新手(linux 用户):
您还可以在 ~/.bashrc 目录中创建一些不错的可读函数,例如:

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

并在终端中像这样使用它:

open htts://google.com

对于 macOS 你可以使用这个命令:

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