From Netsoc Wiki
Revision as of 21:09, 7 September 2018 by Dario (talk | contribs)
Jump to: navigation, search

Tmux is a terminal multiplexer, which allows you to to run multiple terminal sessions in one remote session.


A tmux session

Say you wanted to run both chat on IRC and edit a file at the same time. You could open up two separate terminal windows on your own machine, and launch two separate SSH sessions:

$ ssh
$ irssi


$ ssh
$ vim foo.txt

But this is less than ideal - you have to make two separate connections, and you may log out of one and forget to log out of the other. Even worse, if your laptop goes to sleep or you lose connection to the server somehow, your processes will be lost forever.

What you can do instead is launch one SSH session and use tmux to run both IRC and vim simultaneously:

$ ssh
$ tmux

You should find yourself inside a terminal session, within your terminal session. Run irssi as normal, and then press Ctrl-b + c. Now you have an extra "window" to play with. Navigate between your windows with Ctrl-b + n and Ctrl-b + p (n[ext], p[revious]). You can close a window by terminating the process, which also usually involves closing the process and then the shell with Ctrl + d.

Attaching and detaching

If you close your SSH session or lose connection to the server while inside tmux, fear not. You can reattach to your previous tmux session and all your processes will still be running there:

$ ssh
$ tmux a

(tmux a is short for tmux attach)

Useful resources