Where to start First steps track · 15 stages
Linux Labs

tmux — terminal multiplexer

4 min tmux 3.x

Keeps a terminal session alive on the server after an SSH drop; sessions live in memory and don't survive a reboot.

Cheat sheet

6 commands Printable version
  • tmux new -s name new named session
  • tmux ls list sessions
  • tmux attach -t name attach to a session
  • tmux kill-session -t name kill a session
  • Ctrl+b d detach — the session keeps running
  • Ctrl+b c new window

Overview

tmux keeps a terminal session alive on the server: you can detach and come back, and long-running tasks survive an SSH drop. Plus windows and panes within one terminal.

bash
tmux                              # new session
tmux new -s work                  # a named session
tmux ls                           # list sessions
tmux attach -t work               # attach (a -t work — short form)
tmux kill-session -t work         # kill the session

All hotkeys go through a prefix, Ctrl+b, followed by a key.

Options

5
Ctrl+b [         enter copy-mode → arrows/PgUp to scroll; q to exit
                 (in copy-mode: Space to start a selection, Enter to copy)
Ctrl+b ]         paste what was copied

~/.tmux.conf (common settings):

set -g mouse on              # mouse: selection, pane resize, scroll
set -g history-limit 10000   # scrollback length
setw -g mode-keys vi         # vi navigation in copy-mode

From a script: tmux new -d -s job 'long-cmd' (run in the background), tmux send-keys -t job 'cmd' Enter.

Option What it does Example
-s name Name the session on creation — easier to find than by number. tmux new -s work
-t name Target a session for attach, kill-session, send-keys. tmux attach -t work
-l ls List running sessions. tmux ls
-d Create the session already detached — for launching tasks from scripts. tmux new -d -s job 'long-running-command'
send-keys Send keystrokes to a session without attaching to it (for automation). tmux send-keys -t job 'cmd' Enter

Nothing found. Try a shorter query.

Recipes

1

Hotkeys

Ctrl+b  d        detach — the session keeps running
Ctrl+b  c        new window        Ctrl+b  n / p   next/previous window
Ctrl+b  ,        rename the window  Ctrl+b  0..9   jump to window by number
Ctrl+b  w        list windows/sessions (pick one)
Ctrl+b  "        split horizontally (a pane)
Ctrl+b  %        split vertically
Ctrl+b  arrows   move between panes
Ctrl+b  z        zoom the current pane in/out
Ctrl+b  x        close the pane
Ctrl+b  [        scroll/copy mode (q to exit)
Ctrl+b  ?        list of all key bindings

Troubleshooting

4

I can't exit / everything is being "captured"

That's the Ctrl+b prefix. To simply detach — Ctrl+b then d. To close the shell in a pane — exit.

sessions should be nested with care

You ran tmux inside tmux. Detach from the inner one (Ctrl+b d) or don't nest it (send the prefix to the inner session with Ctrl+b Ctrl+b).

Sessions disappeared after a reboot

tmux keeps sessions in memory — a reboot kills them. For services that must stay up, use systemd, not tmux.

Mouse scrolling doesn't work

Enable set -g mouse on in ~/.tmux.conf and tmux source ~/.tmux.conf (or start a new session).

See also

  • ssh-client — Connecting over SSH, copying with scp/rsync, ~/.ssh/config, port forwarding.
  • background-jobs — Running in the background, managing shell jobs so a process survives logout.
Loading…