bash 如何从命令行使用 Chrome 打开文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18472464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I open a file with Chrome from the command line?
提问by
I would like to open a file (index.html) in the current directory with Google Chrome or Chromium from a bash terminal (I'm using Linux Mint 15). What is the command? I've tried the intuitive approaches and have done a few stack and google searches to no avail, oddly overlooked (perhaps painfully obvious). Thanks in advance.
我想使用 Google Chrome 或 Chromium 从 bash 终端(我使用的是 Linux Mint 15)打开当前目录中的文件 (index.html)。命令是什么?我已经尝试了直观的方法,并做了一些堆栈和谷歌搜索无济于事,奇怪地被忽视了(也许很明显)。提前致谢。
hermes@hades ~/coding/.../public $ google-chrome index.html
google-chrome: command not found
hermes@hades ~/coding/.../public $ google-chromium index.html
google-chromium: command not found
采纳答案by konsolebox
Doing some search for chromium you could do it like chromium-browser path|file
.
对铬进行一些搜索,您可以这样做chromium-browser path|file
。
回答by Nick Humrich
Just type in the program name followed by the file:
只需输入程序名称,然后输入文件:
google-chrome {file-path}
ex:
前任:
google-chrome ~/index.html
回答by Evan
Try
尝试
open {filename}
if it's an .html
file it should open in your default browser
如果它是一个.html
文件,它应该在您的默认浏览器中打开
回答by jaygeek
From the bash shell(on Windows), you can use:
从bash shell (在 Windows 上),您可以使用:
start myFilename.html
start myFilename.html
and to open a folder:
并打开一个文件夹:
explorer "C:\Program Files\Git"
explorer "C:\Program Files\Git"
Added for reference, since my search landed here, too.
添加以供参考,因为我的搜索也在这里。
回答by collect
This solution has always worked for me - open -a "google\ chrome.app" index.html
- where "google\ chrome.app" is the name/location of chrome on your system.
这个解决方案一直对我 open -a "google\ chrome.app" index.html
有用——其中“google\ chrome.app”是你系统上chrome的名称/位置。
OR
或者
If Chrome is your default browser, simply - open index.html
如果 Chrome 是您的默认浏览器,只需 - open index.html
回答by Jonathan Nascimento
If Chrome is your main browser, just use
如果 Chrome 是您的主浏览器,只需使用
see your_file.html
回答by Steven K. Mariner
With Chrome notthe default browser, this worked for me under Windows 10:
Chrome不是默认浏览器,这在 Windows 10 下对我有用:
start "New Chrome Window Title" /d "C:\Program Files (x86)\Google\Chrome\Application" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --new-window "file://C:/Folder/SubFolder/Sub Subfolder/thisfile.html"
You'll need:
你需要:
- A way to convert the unqualified filename into a fully qualified filename;
- A way to convert backslashes to forward slashes;
- A way to prefix the "
file://
" onto the URL; - To identify the specific directory in which you find
chrome.exe
; - Decide on whether you want to keep the switch to force a new window;
- And other command line options as pertinent.
- 一种将非限定文件名转换为完全限定文件名的方法;
- 一种将反斜杠转换为正斜杠的方法;
- 一种
file://
在 URL 上添加“ ”前缀的方法; - 确定您在其中找到的特定目录
chrome.exe
; - 决定是否要保持开关强制打开新窗口;
- 和其他相关的命令行选项。
These should be reasonably doable in a .bat
or .cmd
file, using FOR
commands and the text-replacing features of the SET
command; or do all that in a .vbs
or .ps1
script which could be called from the batch file, etc.
这些应该在一个.bat
或.cmd
文件中合理可行,使用FOR
命令和命令的文本替换功能SET
;或者在可以从批处理文件等中调用的.vbs
或.ps1
脚本中执行所有操作。
But the basic syntax appears sound.
但是基本的语法看起来很合理。
回答by Mihai.Mehe
For MacOS, with absolute path (if your Chrome is installed in the /Applications folder) in bash CLI use:
对于 MacOS,使用绝对路径(如果您的 Chrome 安装在 /Applications 文件夹中)在 bash CLI 中使用:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
So, if you want to open the CNN webpage:
所以,如果你想打开 CNN 网页:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome www.cnn.com
回答by Ken
It looks like Chrome is not in your $PATH the way it should be. Easy solution would probably be to uninstall and reinstall Chrome, which should put it in your $PATH. Then
看起来 Chrome 不在您的 $PATH 中。简单的解决方案可能是卸载并重新安装 Chrome,这应该将它放在您的 $PATH 中。然后
google-chrome [file]
should work for you.
应该为你工作。
回答by Vishal
You can open a file using below terminal commands (Linux)
您可以使用以下终端命令打开文件 (Linux)
- Open in New Tab
google-chrome < filepath >
- Open in New Window
google-chrome --new-window < filepath >
- Open in Incognito mode
google-chrome --incognito (--incongnito-mode) < filepath >
- 在新标签页中打开
google-chrome < filepath >
- 在新窗口中打开
google-chrome --new-window < filepath >
- 以隐身模式打开
google-chrome --incognito (--incongnito-mode) < filepath >
<filepath> = localhost/test/../filename.html