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

后端 未结 15 1234
余生分开走
余生分开走 2020-12-25 09:47

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\'v

相关标签:
15条回答
  • 2020-12-25 10:35

    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)
    
    0 讨论(0)
  • 2020-12-25 10:36

    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.

    0 讨论(0)
  • 2020-12-25 10:37

    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.

    0 讨论(0)
提交回复
热议问题