How To Run Firefox From The Command Line

How do I run Firefox browser from the Linux command line (shell prompt)? How to run Firefox from command line on Linux or Unix based server?

You can use the command line as follows with special arguments to start Mozilla firefox browser.

ADVERTISEMENTS

Firefox Start Browser From The Command Line

You can find out full path to firefox with the following type command:
type -a firefox
To open the browser, enter:
$ firefox
OR
$ /usr/bin/firefox

Firefox Open URL

To open URL in a new tab, enter:
$ /usr/bin/firefox --new-window http://www.cyberciti.biz/
To open URL in a new window, enter:
$ /usr/bin/firefox www.cyberciti.biz

Linux run Firefox from the command line

Unix / Linux run Firefox from the command line

Linux Firefox open url in a new tab

You must run:
firefox --new-tab url
/usr/bin/firefox --new-tab https://www.nixcraft.com/

Firefox Search option

You can search words (term) with your default search engine, enter:
$ /usr/bin/firefox --search "term"
$ /usr/bin/firefox -search "linux add user to group"

Open Firefox Options / Preferences

To open Firefox options/preferences window, enter:
$ /usr/bin/firefox --preferences

Set Firefox As Default Browser

To set the Firefox app as the default browser, enter:
$ /usr/bin/firefox --setDefaultBrowser

How Do I Run Firefox Remotely On Server?

SSH is frequently used to tunnel insecure traffic over the Internet in a secure way. You can login to remote server using the ssh client:
$ ssh -X user@server42.nixcraft.com
To run firefox, enter:
$ /usr/bin/firefox &
$ /usr/bin/firefox www.cyberciti.biz

How to run Firefox from a remote server

You need terminal and Gnome/KDE GUI to work with the local desktop. However, if you need to run Firefox on a remote Linux server and get output on a local desktop, try the ssh command:
ssh -X vivek@server1.cyberciti.biz firefox www.cyberciti.biz
One can specify X display to use:
firefox --display=DISPLAY url
firefox --display=0.0 url
DISPLAY=some-desktop:0.0 firefox url
ssh -X vivek@server1.cyberciti.biz "firefox --display=0.0 www.cyberciti.biz"

How to find out all other Firefox command line options?

Run the following command and you can filter outputs using the grep command/egrep command:
firefox --help
firefox --help | grep search

Usage: firefox [ options ... ] [URL]
       where options include:
 
X11 options
  --display=DISPLAY  X display to use
  --sync             Make X calls synchronous
  --g-fatal-warnings Make all warnings fatal
 
Firefox options
  -h or --help       Print this message.
  -v or --version    Print Firefox version.
  -P <profile>       Start with <profile>.
  --profile <path>   Start with profile at <path>.
  --migration        Start with migration wizard.
  --ProfileManager   Start with ProfileManager.
  --no-remote        Do not accept or send remote commands; implies
                     --new-instance.
  --new-instance     Open new instance, not a new window in running instance.
  --UILocale <locale> Start with <locale> resources as UI Locale.
  --safe-mode        Disables extensions and themes for this session.
  -MOZ_LOG=<modules> Treated as MOZ_LOG=<modules> environment variable, overrides it.
  -MOZ_LOG_FILE=<file> Treated as MOZ_LOG_FILE=<file> environment variable, overrides it.
                     If MOZ_LOG_FILE is not specified as an argument or as an environment variable,
                     logging will be written to stdout.
  --headless         Run without a GUI.
  --save-recordings  Save recordings for all content processes to a directory.
  --browser          Open a browser window.
  --new-window <url> Open <url> in a new window.
  --new-tab <url>    Open <url> in a new tab.
  --private-window <url> Open <url> in a new private window.
  --preferences      Open Preferences dialog.
  --screenshot [<path>] Save screenshot to <path> or in working directory.
  --window-size width[,height] Width and optionally height of screenshot.
  --search <term>    Search <term> with your default search engine.
  --setDefaultBrowser Set this app as the default browser.
  --jsconsole        Open the Browser Console.
  --jsdebugger       Open the Browser Toolbox.
  --wait-for-jsdebugger Spin event loop until JS debugger connects.
                     Enables debugging (some) application startup code paths.
                     Only has an effect when `--jsdebugger` is also supplied.
  --devtools         Open DevTools on initial load.
  --start-debugger-server [ws:][ <port> | <path> ] Start the debugger server on
                     a TCP port or Unix domain socket path. Defaults to TCP port
                     6000. Use WebSocket protocol if ws: prefix is specified.
  --recording <file> Record drawing for a given URL.
  --recording-output <file> Specify destination file for a drawing recording.
 
      -g or --debug          Start within debugger
      -d or --debugger       Specify debugger to start with (eg, gdb or valgrind)
      -a or --debugger-args  Specify arguments for debugger
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
23 comments… add one
  • anonymous Apr 2, 2011 @ 11:34

    hello,

    the shell comand “firefox” does only work if you start in from a e.g. gnome terminal, and gnome is running on this display.

    what is the command if you want start friefox e.g on tty1 , where no desktop is running?

    linux says ” error : no display specified”
    How to specify the display ?

    or does it only work when starting from tty7 (where the desktop is running) in this case i’m wondering about the advantage starting from a shell. because you could also click on the firefox button in front panel.

    thx for advice

    • AnonimousTwo May 5, 2012 @ 18:32

      You need 2 command lines. (you do not need to be logged as root)

      But first you need :
      To get the X server installed = xserver-xorg
      To get a graphical interface installed : Gnome or KDE or LXDE or XFCE or whatever you want…
      To be located and log on in a TTY console

      The first command line is to set the variable “DISPLAY” to “:0” by the following :
      username@localhost:~$ export DISPLAY=:0

      To verify your work has been done efficiently you may enter, to see the value of your variable :

      username@localhost:~$ echo $DISPLAY

      You should get :
      :0

      The second one by entering the program name you need to run, iceweasel for exemple :
      username@localhost:~$ /usr/lib/iceweasel/firefox.bin http://www.debian.org &

      NOTA : The sign “&” at the end gives you back the command line available.

      …and it will start firefox on the web page http://www.debian.org in you graphical interface…

      Have fun and thank you !!! So much !!!

  • AnonimousTwo May 5, 2012 @ 18:46

    My previous topic gives you how to start a graphical software in tty7 from a command line in tty console like tty1 to tty6.
    It’s helpfull to run a software remotly.
    You need to get you desktop environment started.
    By I should know, it’s not possible to start a graphical software from the console without your desktop environment started.
    If you want to navigate on the Internet by a command line software in text mode from the console, you should use “Lynx”

  • Kent Bye Sep 4, 2012 @ 0:27

    open -a /Applications/Firefox.app http://example.com is what I use from the Mac terminal

  • Gokul Jan 16, 2013 @ 17:50

    HI Vivek,

    I removed firefor old version using yum command. And downloaded firefox 18 .tar.bz2.

    Unzipped the tar file in /home/user/firefox.

    [root@localhost firefox]# /usr/bin/firefox
    bash: /usr/bin/firefox: No such file or directory

    Is that any settings i need to do?

    • vijay Apr 4, 2013 @ 11:50

      you need to install the package and then see the following is present
      /usr/bin/firefox

  • Anonymous May 13, 2013 @ 22:31

    Hey I was wondering if I could close a tab in terminal? i wanted to run a bash script that opened a particular window and close it. for example i have

    #!/bin/bash

    firefox http://www.google.com –new-window

    now i’m stuck with an open window i want to close. Is there a way to do it in terminal?

  • c Dec 20, 2013 @ 6:47

    Open new tab:
    $ /usr/bin/firefox -new-window https://www.cyberciti.biz/
    change new-window for new-tab

  • gopu Jan 20, 2014 @ 18:32

    How to keep alive firefox from ssh command. actually i want to keep alive firefox & open tabs after vnc viewer off. i m using skype form vps vnc viewer & skype via http://www.plus.im. so i want to know how to keep alive that firefox pages.

    thanks.

  • gopu Jan 22, 2014 @ 11:53

    solve this problem with skype/vnc/ubuntu.

  • Tyler Aug 15, 2014 @ 18:48

    Dear Editor,

    under Firefox Open URL, -new-window is used to open a new window and will not open a tab. Simple typo anyone could make. :)

  • stanislav Jan 20, 2015 @ 23:15

    #!/bin/bash
    if ps aux | grep “midori” | grep -v grep ; then env DISPLAY=:0 midori ; fi

    do nothing :(

  • Bhumi Feb 5, 2015 @ 12:09

    How can i start firefox using exec command in php? i am using ubuntu.

  • derZimmermann Aug 29, 2015 @ 9:42

    if you want that the browser stay open when closing the executing terminal session you have to use the nohup command.
    In my case:

    export DISPLAY=:0";"nohup /usr/lib/iceweasel/iceweasel URLOFWEBSITE &

    worked fine.

  • surendar Mar 31, 2016 @ 14:17

    how to open firefox in private window ..in linux pls help

  • ssugat Nov 9, 2016 @ 16:08

    could you help me figure out what settings might not be in place in my machine.

    I run
    export DISPLAY=:0.0

    followed by firefox and I get error message saying,

    Error: cannot open display: :0.0

    How do I troubleshoot what might not be right in my machine?

  • nate.sturtz@sturtz.ml Aug 10, 2020 @ 20:25

    How do i contaol firefox from cli
    this is what I get
    Invalid MIT-MAGIC-COOKIE-1 keyUnable to init server: Could not connect: Connection refused
    Error: cannot open display: :0

    • 🐧 Vivek Gite Aug 11, 2020 @ 11:45

      Are you running command from remote host? Try setting DISPLAY variable:
      export DISPLAY=:0
      OR
      export DISPLAY=:1

  • Anonymous Sep 25, 2020 @ 20:24

    Is there a way to pull down a webpage via the firefox command line options and save to a file? I’d like to mimic all the environment of a browser, but still run it in headless mode so I don’t have to be in display mode. Also, yes I understand wget/curl/w3m/etc options like this, but wanted to see if the firefox command line option also exists.
    Thanks,

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.