In Ubuntu, I use the default gnome-terminal to run my commands. I typically have a couple of windows open, each with several tabs. When my OS crashes∗, for whatever reason, and I reboot, I lose all these terminals.

Sublime Text, Firefox and Chrome have spoilt me, as all of them give me the option to restore all the windows and tabs to exactly what they were doing prior to the crash, and I would like to be able to do the same with my terminal windows and tabs.

How can this be accomplished?

Spelling out the specifics of what I would like:

  • Must have:
    • Upon reboot, when I open terminal for the first time, the windows and tabs that were there before get re-opened
      • Either with or without a prompt is fine
    • Each tab is cd-ed into the folder that it was in before
  • Nice to have:
    • The bash_history for that tab is still there
    • so when I press the "up" and "down" keys, I would get what I expect within that tab

∗ Ubuntu running on a laptop whose drivers are not the most friendly, happens more often than I would like (in case you are wondering)

  • Are you maybe looking for something like this? – terdon Feb 28 '14 at 15:04

The closest they could get was.

You can use the following options:

--save-config=FILE              Save the terminal configuration to a file
--load-config=FILE              Load a terminal configuration file


To save:

gnome-terminal --save-config=/tmp/cfgtab

To load it back:

gnome-terminal --load-config=/tmp/cfgtab

enter image description here

  • @tiagoc Hmm - does this work globally - i.e. if I execute this command from any shell/ terminal, it will save the context from every currently open one? ... 'Cos if so, what I'm thinking is I could set up a cron job, or even just a simple watch -n5 gnome-terminal --save-config=/tmp/cfgtab and upon a crash I can simply reload the sessions by running gnome-terminal --load-config=/tmp/cfgtab manually. – bguiz Feb 27 '14 at 23:48
  • @bguiz Yes, at least the current working directory of each tab is saved. As the typed commands, everything is saved to bash_history. While remembering the commands in a tab in particular I think it is not possible to do this. – stderr Feb 27 '14 at 23:58
  • Unfortunately, the new gnome-terminal in Gnome 3 has dropped support for loading and saving configs :-( – Neil Mayhew Oct 20 '15 at 20:25

Here is the solution that I came up with:


It is a shell script that automates the above.

For normal use:


After a crash and reboot:

~/watcher.sh restore
  • @tiagoc I have come up with my solution inspired by yours. I'll give you a +1 and check, since you led me to the solution - thanks! – bguiz Feb 28 '14 at 0:48
  • @tiagoc would you share the solution you came up with? – gene_wood Jun 2 '15 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.