user2719351
user2719351

Reputation:

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

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).

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

Upvotes: 78

Views: 161553

Answers (18)

Eldorado
Eldorado

Reputation: 87

You need to find the location of chrome.exe on your system. If Chrome was installed into a default location, the Shell command in Windows looks like this:

"C:\Program Files\Google\Chrome\Application\chrome.exe"

Further, if you want to open a particular page in Chrome:

"C:\Program Files\Google\Chrome\Application\chrome.exe" "https://google.com"

Upvotes: 0

Andrew Simmons
Andrew Simmons

Reputation: 63

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

explorer.exe index.html

Upvotes: 0

AzReaL
AzReaL

Reputation: 23

Try this

start chrome "file or path"

same for FireFox

start firefox "file or path"

This worked for me.

Upvotes: -1

Vishal Kumar
Vishal Kumar

Reputation: 1378

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

Upvotes: 5

Astm
Astm

Reputation: 1720

For Mac i'm using

open -a 'google chrome' /yourPath

Upvotes: 33

Ken
Ken

Reputation: 61

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.

Upvotes: 5

Mihai.Mehe
Mihai.Mehe

Reputation: 504

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

Upvotes: 4

fedorqui
fedorqui

Reputation: 289695

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)

Upvotes: 1

Nick Humrich
Nick Humrich

Reputation: 15755

Just type in the program name followed by the file:

google-chrome {file-path}

ex:

google-chrome ~/index.html

Upvotes: 73

Evan
Evan

Reputation: 561

Try

 open {filename}

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

Upvotes: 56

Steven K. Mariner
Steven K. Mariner

Reputation: 441

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.

Upvotes: 3

Hicham Alaoui
Hicham Alaoui

Reputation: 21

  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.

Upvotes: 2

typo
typo

Reputation: 1071

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

Upvotes: 10

jaygeek
jaygeek

Reputation: 1172

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.

Upvotes: 24

Jonathan Nascimento
Jonathan Nascimento

Reputation: 145

If Chrome is your main browser, just use

see your_file.html

Upvotes: 8

mxro
mxro

Reputation: 6878

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.

Upvotes: 1

konsolebox
konsolebox

Reputation: 75488

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

Upvotes: 17

alexkonradi
alexkonradi

Reputation: 750

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

Upvotes: 2

Related Questions