Terminal multiplexers
“Terminal Multiplexers”, like screen and tmux, are extremely useful tools for running jobs on the department servers. The primary reason to use them is so you can run a job on the server and not need to keep your connection with the server open (e.g. you can close your computer, go to sleep, etc. while your job runs). It’s often the case that your connection to the server might disconnect even if your computer just goes to sleep or disconnects from the internet for a minute.
There are two major terminal multiplexer options: screen and tmux. The Internet recommends tmux (but some people in the department use screen).
In terms of usage, the most important commands 1. creating a new session 2. detaching but not closing as session 3. reattaching a session and 4. closing a session.
With these four options you can start up a session (1), step away from a session / the server without killing a job you’re running (2), come back to the session you left (3) and close a session once you’re done with it (4). The rest of the commands are icing on the cake.
In the following sections below, we’ll present pros of both, then present sections on standard commands for both approaches. This article is currently more a place to remind yourself of what commands to use than a new introduction to the ideas. We recommend reading either of the introductions (at the end of either tool’s subsection) for get exposure to the power of these tools.
Comparisons
tmux:- more consistent syntax (but
screenis still pretty good) - preserves panels / windows even when you detach the session
- maybe a little safer in closing sessions (confirms request)
- more consistent syntax (but
screen:- a stable tool (
tmuxis a little more in flux)
- a stable tool (
screen
Basic commands
| Action | Command | Notes |
|---|---|---|
| Start new session [important] | screen
|
|
| Starting a named session | screen -S _session_name_
|
|
| List current sessions | screen -list
|
|
| Detach session [important] | (Ctrl+a)+d
|
|
| Attach/ reopen session [important] | screen -r _session_name_
|
If only one session is open you can just use screen -r
|
| Close session [important] | Ctrl+d
|
|
| Kill a session you are not currently in | screen -XS _session_name_ quit
|
|
| enter scrollback/copy mode | Ctrl+a+[
|
|
| end scrollback/paste buff | Ctrl+a+]
|
Window/panel based commands
Having multiple panels / windows going in a single session at the same time.
| Action | Command | Notes |
|---|---|---|
| Create new window | (Ctrl+a)+c
|
|
| split terminal horizontally, and create a new window | (Ctrl+a)+S + (Ctrl+a)+c
|
Note the capital S. |
| split terminal vertically, and create a new window | (Ctrl+a)+| + (Ctrl+a)+c
|
This only works if the screen is a high enough version. |
| move between windows | (Ctrl+a)+ …
|
|
| - next window | +n
|
|
| - previous window | +p
|
|
| - pick from list | +"
|
|
| Move between splits | (Ctrl+a)+ Tab |
External Links
- Introduction: howtogeek.com, linuxize.com
- Cheat sheets: pixelbeat.org.
tmux
Basic commands
| Action | Command | Notes |
|---|---|---|
| Start session [important] | tmux
|
|
| Start named session | tmux new -s _session_name_
|
|
| Rename session | (Ctrl+b)+: -> then rename-session -t _current_name_ _new_name_
|
You don’t have to include -t _current_name_ if you want to rename a session you are in.
|
| Detach session [important] | (Ctrl+b)+d
|
|
| Attach/ reopen session [important] | tmux attach-session -t _session_name_
|
|
| Close session [important] | tmux kill-session -t _session_name_
|
|
| List current sessions | tmux ls
|
Window/panel based commands
Having multiple panels / windows going in a single session at the same time.
| Action | Command | Notes | |
|---|---|---|---|
| new window | (Ctrl+b)+c
|
||
| see window numbering | (Ctrl+b)+q
|
flashes number of each panel open | |
| close current window | (Ctrl+b)+& -> then y close current window
|
||
| create panel splitting | (Ctrl+b)+ …
|
||
| - horizontal splitting | +”
|
this is capital"
| |
| - vertical splitting | +%
|
this is also a capital %
| |
| - move between panels | + arrow keys
|
||
| move between windows | (Ctrl+b)+ …
|
||
| - next window | +n
|
||
| - previous window | +p
|
External Links
- Introduction: howtogeek.org
- Cheat sheets: howtogeek.org (see the bottom of the article).