EMZETT.
Login

tmux and screen: several terminals in one

In short: tmux (and the older screen) is a terminal multiplexer: you have several windows in one session, and the session keeps running even if the connection (for example SSH) drops.

Why it is useful

Long jobs (updates, compiling, downloads) would otherwise stop when you lose the connection or close the window. In tmux the session keeps running on the server and you attach again later.

Most important commands

The prefix is Ctrl+B, followed by a key.

  • tmux starts a session, tmux new -s name with a name.
  • Ctrl+B d detaches the session (it keeps running). tmux attach -t name reconnects; tmux ls lists.
  • Ctrl+B c new window, Ctrl+B n / p next/previous.
  • Ctrl+B % splits vertically, Ctrl+B " horizontally, Ctrl+B + arrow switches the pane.
  • Ctrl+B [ scroll mode (leave with q).

screen

Similar, prefix Ctrl+A: screen -S name, detach with Ctrl+A d, screen -r name. It is older and simpler; tmux is more common today.

Tip

On remote servers you get used to it: tmux first, then work. A file ~/.tmux.conf allows own settings, see Dotfiles and configuration management.

See also: Terminal text editors