# Tmux/GNU Screen

Tmux is the best command-line screen manager. Screen is its predecessor.

### When/Why do you need it?

Tmux/screen lets you tile window panes in a command-line environment (see the screenshot below). So that you can run, or keep an eye on, multiple programs within one terminal; and minimize (detach) them when you close the connection, and restore them back in afterwards (reattach).

A common use-case is when you interactively train a model on a GPU node, or donwload large files on a transfer node. These tasks take a long time, and you may want to keep them running when you close the SSH and leave office.  Tmux/screen allows you to run model training and data download in a specifc "container" of command-line apps, such that you can minimize/detach them when you close the SSH, and open/reattach them when you are back and quickly check their running status.

Another common use-case for tmux/screen is on a remote server where you have a common layout that you always use (say, Vim + IPython), and want a way to quickly jump into and out of. An example would be if you’re connecting through a login server and have other remote SSH sessions you would like to be connected to simultaneously. Similarly, if you have to hop into [Vim](https://zhanglab-aim.gitbook.io/labwiki/handbook/hpc-usage/vim-setup), you can use tmux to give you access to your shell or a REPL in the same terminal window for a IDE-like experience.

<figure><img src="https://upload.wikimedia.org/wikipedia/commons/5/50/Tmux.png" alt=""><figcaption><p>Who doesn't like a geeky-look in their terminal?!</p></figcaption></figure>

### Getting Started

By default screen is available on the 2013 Cisco cluster, and both tmux and screen are available on the 2022 HPE cluster. You can install a local version of Tmux on Cisco cluster. Because Tmux is almost better than Screen on every aspect, we will focus on Tmux; but GNU screen usage should be highly similar if you just google it.

#### Start new named session:

`tmux new -s [session name]`

#### Detach from session:

`ctrl+b d`

#### List sessions:

`tmux ls`

#### Attach to named session:

`tmux a -t [name of session]`

#### Kill named session:

`tmux kill-session -t [name of session]`

#### Split panes horizontally:

`ctrl+b "`

#### Split panes vertically:

`ctrl+b %`

#### Kill current pane:

`ctrl+b x`

#### Move to another pane:

`ctrl+b [arrow key]`

### Useful Links

Tmux cheatsheet: <https://tmuxcheatsheet.com/>
