DEV Community

Michael Saparov
Michael Saparov

Posted on

tmux: a modern replacement for screen

Tmux is a terminal multiplexer. It lets you run multiple programs in a single terminal, detach them (so they keep running in the background), and later reattach from another terminal.
If you’ve used GNU screen before, tmux will feel familiar — but more flexible and actively maintained.
Tmux has three core concepts: session, window, and pane.

  • Session — groups one or more windows together.
  • Window — groups one or more panes; a session can have multiple windows.
  • Pane — a split area inside a window that contains a terminal with a running program.

Sessions.

Start a session.

To start working with tmux, create a session. If you don’t specify a name, tmux will assign one automatically:

tmux
Enter fullscreen mode Exit fullscreen mode

To create a session with a custom name:

tmux new -s session_name
Enter fullscreen mode Exit fullscreen mode

After creating a session, tmux attaches you to automatically.

Leaving a session.

There are two ways to leave a tmux session:
Detach from the session — the session keeps running in the background:

Ctrl+b d
Enter fullscreen mode Exit fullscreen mode

Exit the shell — the session will be destroyed if no windows remain:

Ctrl+D
Enter fullscreen mode Exit fullscreen mode

Managing sessions.

To see all running sessions:

tmux ls
Enter fullscreen mode Exit fullscreen mode

To attach to a session: Attach to the only (or last used) session:

tmux attach
Enter fullscreen mode Exit fullscreen mode

Attach to a specific session by name:

tmux attach -t session_name
Enter fullscreen mode Exit fullscreen mode

Windows.

A window in tmux is similar to a tab in a terminal emulator.

Create a window.

To create a new window, use:

Ctrl+b c
Enter fullscreen mode Exit fullscreen mode

Switching between windows.

Switch to the next or previous window:

Ctrl+b n
Ctrl+b p
Enter fullscreen mode Exit fullscreen mode

Switch to a window by number:

Ctrl+b 0
Ctrl+b 1
Ctrl+b 2
Enter fullscreen mode Exit fullscreen mode

Show the window list:

Ctrl+b w
Enter fullscreen mode Exit fullscreen mode

Panes.

A pane is a split area inside a tmux window. Each pane runs its own shell or program.

Split panes.

Split the current window vertically:

Ctrl+b %
Enter fullscreen mode Exit fullscreen mode

Split the current window horizontally:

Ctrl+b "
Enter fullscreen mode Exit fullscreen mode

Switching between panes.

Move to the next pane:

Ctrl+b o
Enter fullscreen mode Exit fullscreen mode

Switch to a specific pane using arrow keys:

Ctrl+b ←
Ctrl+b →
Ctrl+b ↑
Ctrl+b ↓
Enter fullscreen mode Exit fullscreen mode

Resize panes.

Resize the current pane:

Ctrl+b Ctrl+←
Ctrl+b Ctrl+→
Ctrl+b Ctrl+↑
Ctrl+b Ctrl+↓
Enter fullscreen mode Exit fullscreen mode

Closing panes.

Close the current pane by exiting the shell:

Ctrl+D
Enter fullscreen mode Exit fullscreen mode

Top comments (0)