How to save current tmux session¶
To preserve your tmux session across reboots, you can use a combination of tmux and a tool called tmux-resurrect. tmux-resurrect allows you to save and restore tmux sessions, including the state of each pane and window.
Here are the steps to install and use tmux-resurrect:
-
Install
tmux-resurrect:First, you need to install
tmux-resurrect. You can do this by cloning the repository and adding it to yourtmuxconfiguration.git clone https://github.com/tmux-plugins/tmux-resurrect ~/tmux-resurrect -
Configure
tmuxto usetmux-resurrect:Add the following lines to your
~/.tmux.conffile to enabletmux-resurrect:set -g @plugin 'tmux-plugins/tmux-resurrect' run-shell ~/tmux-resurrect/resurrect.tmuxIf you don't have a
~/.tmux.conffile, you can create one. -
Reload
tmuxconfiguration:After updating your
~/.tmux.conf, reload thetmuxconfiguration by running the following command inside atmuxsession:tmux source-file ~/.tmux.conf -
Save the
tmuxsession:Before rebooting, save your
tmuxsession by pressing the following key combination inside atmuxsession:Prefix + Ctrl-sThe default
Prefixkey isCtrl-b. So, you would pressCtrl-bfollowed byCtrl-s. -
Reboot your system:
You can now safely reboot your system.
sudo reboot -
Restore the
tmuxsession:After the system reboots, start a new
tmuxsession and restore the saved session by pressing the following key combination inside the newtmuxsession:Prefix + Ctrl-rAgain, the default
Prefixkey isCtrl-b. So, you would pressCtrl-bfollowed byCtrl-r.
By following these steps, you can save and restore your tmux sessions across reboots, ensuring that you don't lose your work.