How do I open a file with Chrome from the command line?

BashGoogle Chrome

Bash Problem Overview


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.

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

Bash Solutions


Solution 1 - Bash

Just type in the program name followed by the file:

google-chrome {file-path}

ex:

google-chrome ~/index.html

Solution 2 - Bash

Try

 open {filename}

if it's an .html file it should open in your default browser

Solution 3 - Bash

From the bash shell (on Windows), you can use:

start myFilename.html

and to open a folder:

explorer "C:\Program Files\Git"

Added for reference, since my search landed here, too.

Solution 4 - Bash

For Mac i'm using

open -a 'google chrome' /yourPath

Solution 5 - Bash

Doing some search for chromium you could do it like chromium-browser path|file.

Solution 6 - Bash

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.

OR

If Chrome is your default browser, simply - open index.html

Solution 7 - Bash

If Chrome is your main browser, just use

see your_file.html

Solution 8 - Bash

You can open a file using below terminal commands (Linux)

  1. Open in New Tab google-chrome < filepath >
  2. Open in New Window google-chrome --new-window < filepath >
  3. Open in Incognito mode google-chrome --incognito (--incongnito-mode) < filepath >
<filepath> = localhost/test/../filename.html

Solution 9 - Bash

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

google-chrome [file] 

should work for you.

Solution 10 - Bash

For MacOS, with absolute path (if your Chrome is installed in the /Applications folder) in bash CLI use:

 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

So, if you want to open the CNN webpage:

 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome  www.cnn.com

Solution 11 - Bash

With Chrome not the default browser, this worked for me under 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.

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.

But the basic syntax appears sound.

Solution 12 - Bash

On Ubuntu 12.04, at least, it's /opt/google/chrome/chrome; I've also got a symlink to it at /usr/bin/google-chrome

Solution 13 - Bash

  1. In bash or git CMD, make sure you are in your project directory/folder
  2. Type start index.html
  3. Hit Enter. Voila :-) you're done

This worked for me. Hope it does for you too.

Solution 14 - Bash

Try

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

Or

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

--allow-file-access-from-files will relax some security settings , useful for testing with local files.

Solution 15 - Bash

As others stated, the solution is to use:

google-chrome www.google.com

You can also use --incognito to open them in incognito mode:

google-chrome --incognito www.google.com

Note you can open multiple pages at the same time by just placing them one after the other:

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

If you want to open them from a file, use the command substitution $() to open it and process on the fly:

google-chrome $(<file)

Solution 16 - Bash

None of the other things I saw worked for me, but I later found this that worked:

explorer.exe index.html

Solution 17 - Bash

Try this

start chrome "file or path"

same for FireFox

start firefox "file or path"

This worked for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2719351View Question on Stackoverflow
Solution 1 - BashNick HumrichView Answer on Stackoverflow
Solution 2 - BashEvanView Answer on Stackoverflow
Solution 3 - BashjaygeekView Answer on Stackoverflow
Solution 4 - BashAstmView Answer on Stackoverflow
Solution 5 - BashkonsoleboxView Answer on Stackoverflow
Solution 6 - BashtypoView Answer on Stackoverflow
Solution 7 - BashJonathan NascimentoView Answer on Stackoverflow
Solution 8 - BashVishal KumarView Answer on Stackoverflow
Solution 9 - BashKenView Answer on Stackoverflow
Solution 10 - BashMihai.MeheView Answer on Stackoverflow
Solution 11 - BashSteven K. MarinerView Answer on Stackoverflow
Solution 12 - BashalexkonradiView Answer on Stackoverflow
Solution 13 - BashHicham AlaouiView Answer on Stackoverflow
Solution 14 - BashmxroView Answer on Stackoverflow
Solution 15 - BashfedorquiView Answer on Stackoverflow
Solution 16 - BashAndrew SimmonsView Answer on Stackoverflow
Solution 17 - BashAzRaeLView Answer on Stackoverflow