2013-08-27 134 views
29

我想用bash終端(我使用Linux Mint 15)在Google Chrome或Chromium中打開當前目錄中的文件(index.html)。命令是什麼?我嘗試了直觀的方法,並做了一些堆棧和谷歌搜索無濟於事,奇怪地忽略(也許痛苦地顯而易見)。提前致謝。如何從命令行使用Chrome打開文件?

[email protected] ~/coding/.../public $ google-chrome index.html 
google-chrome: command not found 
[email protected] ~/coding/.../public $ google-chromium index.html 
google-chromium: command not found 
+3

如果Chrome設爲默認瀏覽器,只需使用'打開index.html'。否則,打開-a(chrome location)index.html' – vroomfondel

+0

這應該是至少在Mac上被接受的答案。 – chovy

+1

@chovy不幸的是,這不是關於Mac。 – konsolebox

回答

7

做鉻你可以做一些搜索它像chromium-browser path|file

+0

'$ chromium-browser -bash:chromium-browser:command not found' – chovy

+0

@chovy這可能意味着你沒有'鉻browser'。 – konsolebox

2

在Ubuntu 12.04上,至少是/opt/google/chrome/chrome;我也有一個符號鏈接到它在/usr/bin/google-chrome

32

在節目名稱只需鍵入後跟文件:

google-chrome {file-path} 

例如:

google-chrome ~/index.html 
+1

這不適用於我...我將編輯上面與終端輸出 – shitgeist

+0

好吧。我們需要找到你有哪個鉻。 CD到'/ usr/bin'並做一個''查找。 -name * chrome *'如果你沒有得到任何東西,請嘗試'查找。名*鉻*'讓我知道你得到什麼。 –

+0

google-chrome不在/ usr/bin中,也不是鉻 – neaumusic

1

嘗試

/opt/google/chrome/google-chrome --allow-file-access-from-files index.html 

或者

/usr/bin/google-chrome --allow-file-access-from-files index.html 

--allow-file-access-from-files會放鬆一些security settings,與本地文件測試非常有用。

23

嘗試

open {filename} 

如果它是一個.html文件,它應該在您的默認瀏覽器中打開

+5

僅適用於mac .... – Mannu

4

如果Chrome是你的主要瀏覽器,只需使用

see your_file.html 
7

的bash shell(在Windows上),您可以使用:

start myFilename.html

,並打開文件夾:

explorer "C:\Program Files\Git"

新增參考,因爲我的搜索降落在這裏,太。

+1

搜索登陸我也在這裏,這正是我一直在尋找的。 – CaRDiaK

8

此解決方案一直爲我工作 - open -a "google\ chrome.app" index.html - 其中「google \ chrome.app」是系統上chrome的名稱/位置。

OR

如果Chrome爲默認瀏覽器,只需 - open index.html

+0

這是非常正確的^^。 – Picrasma

0
  1. 在bash或混帳CMD,確保你在你的項目目錄/文件夾
  2. 類型start index.html
  3. 命中輸入。Voila :-)你完成了

這對我有效。希望它也適合你。

2

有了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" 

你需要:

  • 的一種方式,以不合格的文件名轉換成一個完全合格文件名;
  • 將反斜槓轉換爲正斜槓的方法;
  • 一種將「file://」作爲URL前綴的方式;
  • 確定您發現的特定目錄chrome.exe;
  • 決定是否要保持開關強制一個新窗口;
  • 和其他命令行選項相關。

這些應該在一個或.bat文件.cmd合理可行的,使用FOR命令和SET命令的文本替換特徵;或者執行.vbs.ps1腳本中的所有內容,這些腳本可以從批處理文件中調用等。

但是基本的語法看起來很健全。

0

正如其他人所說,該解決方案是使用:

google-chrome www.google.com 

您還可以使用--incognito在隱身模式下打開它們:

google-chrome --incognito www.google.com 

注意,你可以在同一時間打開多個頁面通過一個接一個地放置它們:

google-chrome www.google.com www.yahoo.com 

如果你想打開它們來回m是一文件,使用命令替換$()打開它,並處理對飛:

google-chrome $(<file) 
相關問題