Is there any way to save a tmux session? In other words, if I reboot the computer, will I always lose the sessions?
Yes, if you reboot you computer you will lose the sessions. Sessions cannot be saved. But, they can be scripted. What most do in fact is to script some sessions so that you can re-create them. For instance, here's a trivial shell script to create a session:
#!/bin/zsh SESSIONNAME="script" tmux has-session -t $SESSIONNAME &> /dev/null if [ $? != 0 ] then tmux new-session -s $SESSIONNAME -n script -d tmux send-keys -t $SESSIONNAME "~/bin/script" C-m fi tmux attach -t $SESSIONNAME
Here's what it does. First, it checks if there's any session already with that name (in this case, the very original name is "script") with tmux has-session. It checks the return code. If there's a ongoing session with that name already, it skips the "if" cycle and go straight to the last line, where it attaches to the session. Otherwise, it creates a session and sends some keys to it (just running a random script for now). Then it exits the "if" block and attaches.
This is a very trivial sample. You can create multiple windows, panes, and the like before you attach.
This will not be the very same thing you asked for, though. If you do any changes to the session, for instance you rename a window and create a new pane in it, if you reboot those changes won't of course be saved.
My main source of informations was "The Pragmatic Bookshelf" Tmux book.
I wrote a simple bash script that persists open tmux sessions, windows and current working directories in each.
Call it like so manually or periodically from cron (because you might forget):
It will write to
~/.tmux-session. Restore them after reboot like so:
I find this much better than a several hundred line long Perl script.
I wrote a tmux plugin that enables you to save complete tmux environment and restore it later. It strives to be really detailed so that you have a feeling you never quit tmux.
Update: now there's a tmux-continuum plugin that performs automatic background saves of tmux environment. Optionally it also *automatically* restores tmux env after computer reboot.
protected by Community♦ Sep 8 '14 at 13:19
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?