-
Notifications
You must be signed in to change notification settings - Fork 4
Using tmux
A typical problem when connecting to a remote machine is that if the connection drops, the remote server will believe we are no longer interested in it and will kill our session. If we were performing some analysis, it would be terminated and we'd have to run it again.
Sometimes the analysis is long, and even if we have a stable connection we need to keep our computer on
just to let the remote server know we don't want to close the session.
There is a handy tool to make our life easier: tmux.
With tmux we can create a terminal that will not disappear when we disconnect from a machine,
and that will wait for us to come back when reconnecting to the server.
In this section, we'll see how to
- create a new working session,
- how to connect to an existing session and
- some tricks to use tmux as a pro.
-
Log in to the remote machine.
-
⚠️ First of all, we have to check that no other tmux session is active:tmux ls -
If the previous command gives no output (or a message like "no server running"), then we can create a new session, otherwise we need to attach to the previous session. To create a new tmux session, type this command:
tmux new -s courseWith the -s switch we gave our session a handy nickname ("course"), but it's not mandatory to do so, but can be very helpful.
- Now we are inside our tmux session and ready to work. If we close the terminal window, we don't lose what we were doing.
- To re-attach to our previous session:
tmux attach -t course
Since tmux shows us a Linux terminal, when we type we are talking to the terminal itself. So to interact with tmux we need a special shortcut: Ctrl + b. This triggers tmux to listen to us. Then we can type a second key to specify what we needed:
-
Ctrl + b,cto create a new window inside our session -
Ctrl + b,pto navigate to the previous window -
Ctrl + b,nto navigate to the next window -
Ctrl + b,dto detach from the session: we'll return back to the "parent" terminal where we can reattach to the tmux session withtmux attach -t course.
For more information you can read this guide or this introduction to tmux.
· Bioinformatics at the Command Line - Andrea Telatin, 2017-2020
Menu