How can I restart Firefox from the command-line and restore the previous state completely (or as much as possible) after restart? Sure, I can do something like
killall firefox; firefox, but that would not restore the session.
I think you need to do a setting in firefox before you restart it from command line. Go to:
Prefrences->General->When Firefox starts
and select :
Show my windows and tabs from last time
then from the command line , restart it the way you like ( may be
killall firefox; firefox&) and you ll get the desired result.
For more advance tuning about session restore you can type
about:config in address bar and search for session or restore to change it.
If you desire to restart Firefox with two or more profiles, this Bash script appears to work consistently:
#!/bin/bash killall -s SIGTERM firefox; sleep 60 firefox -P "user" & firefox -P "default settings" &
Replace the quoted profile names with your own (see
about:profiles). Use the
-foreground flag to control which windows appears on top, if desired.
As noted by the other answers, enable the 'open previous windows and tabs' setting in the preferences (
The value in
sleep 60 (seconds) can potentially be lowered.
Unfortunately, there's no easy way to accomplish this. The closest thing to it would actually be using the Firefox Console (
F2) and typing in
Aside from that, one could install an Addon or take @terdon's advice in his answer and change Firefox Preferences to "Show my windows and tabs from last time" When Firefox starts and "restarting" with
$ killall firefox; sleep 1; firefox &
UPDATE: The "gcli" was removed from firefox in 2018. Therefore, the "Shift+F2" shortcut no longer works.
As of 2020, edit advanced settings via
about:config, search for
resume and set the
browser.sessionstore.resume_session_once flag to
true, then exit.
Here's documentation on the flag: https://kb.mozillazine.org/Browser.sessionstore.resume_session_once