tmux: a modern replacement for screen
Source: Dev.to
Overview
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.
- 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
Creating a session
If you don’t specify a name, tmux will assign one automatically:
tmux
Create a session with a custom name:
tmux new -s session_name
After creating a session, tmux attaches you to it automatically.
Detaching and exiting
-
Detach from a session (leaves it running in the background):
Ctrl+b d -
Exit the shell; the session will be destroyed if no windows remain:
Ctrl+D
Managing sessions
-
List all running sessions:
tmux ls -
Attach to the only (or last used) session:
tmux attach -
Attach to a specific session by name:
tmux attach -t session_name
Windows
A window in tmux is similar to a tab in a terminal emulator.
Creating and navigating windows
-
Create a new window:
Ctrl+b c -
Switch to the next or previous window:
Ctrl+b n(next)
Ctrl+b p(previous) -
Switch to a window by number (e.g., 0, 1, 2):
Ctrl+b 0Ctrl+b 1Ctrl+b 2 -
Show the window list:
Ctrl+b w
Panes
A pane is a split area inside a tmux window. Each pane runs its own shell or program.
Splitting panes
-
Split the current window vertically:
Ctrl+b % -
Split the current window horizontally:
Ctrl+b "
Moving between panes
-
Move to the next pane:
Ctrl+b o -
Switch to a specific pane using arrow keys:
Ctrl+b ←Ctrl+b →Ctrl+b ↑Ctrl+b ↓
Resizing panes
Ctrl+b Ctrl+← # shrink left
Ctrl+b Ctrl+→ # enlarge right
Ctrl+b Ctrl+↑ # enlarge up
Ctrl+b Ctrl+↓ # shrink down
Closing a pane
Close the current pane by exiting the shell:
Ctrl+D