DEV Community

Cover image for tmux: Persistent Terminal Sessions for Developers
Sysemperor
Sysemperor

Posted on • Originally published at sysemperor.com

tmux: Persistent Terminal Sessions for Developers

I lost three hours of work to a dropped SSH connection before I learned about tmux. One detached session later and that problem stopped existing entirely. If you spend any meaningful time on remote servers, tmux is the single highest-leverage tool you can add to your workflow.

Two things make it worth learning: sessions survive after you close your terminal or lose an SSH connection — your processes keep running and you reconnect to find everything exactly where you left it. And you can split a single terminal into multiple panes and windows without juggling tabs.


Install

# Debian / Ubuntu
sudo apt install tmux

# RHEL / Fedora / Rocky
sudo dnf install tmux

# macOS
brew install tmux
Enter fullscreen mode Exit fullscreen mode

Core concepts

tmux has three levels:

  • Session — a collection of windows. One session per project is the natural fit.
  • Window — a full-screen view inside a session. Think of it like a browser tab.
  • Pane — a split region within a window. One window can hold several panes.

The prefix key is how you send commands to tmux without the keystrokes going to the program running inside it. The default is Ctrl+B. Press it, release, then press the command key.


Start and attach to sessions

Create a new named session:

tmux new -s myproject
Enter fullscreen mode Exit fullscreen mode

Detach (session keeps running in the background):

Ctrl+B  d
Enter fullscreen mode Exit fullscreen mode

List sessions:

tmux ls
Enter fullscreen mode Exit fullscreen mode

Reattach by name:

tmux attach -t myproject
Enter fullscreen mode Exit fullscreen mode

Short form: tmux a -t myproject. With only one session, tmux a is enough.

Kill a session:

tmux kill-session -t myproject
Enter fullscreen mode Exit fullscreen mode

Windows

Action Keys
New window Ctrl+B c
Next window Ctrl+B n
Previous window Ctrl+B p
Go to window by number Ctrl+B 0–9
Rename current window Ctrl+B ,
Close current window Ctrl+B &

Windows appear in the status bar at the bottom. The active one has a * next to its name.


Panes

Action Keys
Split top/bottom Ctrl+B "
Split left/right Ctrl+B %
Move between panes Ctrl+B arrow keys
Resize pane Ctrl+B Ctrl+arrow keys
Zoom to full screen Ctrl+B z (toggle)
Close current pane Ctrl+B x

Zoom is one of the most useful shortcuts — it temporarily expands a pane to fill the entire window without closing the others. Hit it again to return to the split view.


Scrollback and copy mode

Mouse scroll does not work inside tmux by default. To scroll:

Ctrl+B  [
Enter fullscreen mode Exit fullscreen mode

This enters copy mode. Arrow keys and Page Up/Page Down navigate. Press / to search, n for the next match, q to exit.


Auto-start a session on login

tmux sessions do not survive a reboot. For development machines where you always want a session waiting:

# add to ~/.bashrc or ~/.zshrc
if [ -z "$TMUX" ]; then
  tmux attach -t main 2>/dev/null || tmux new -s main
fi
Enter fullscreen mode Exit fullscreen mode

The [ -z "$TMUX" ] guard prevents tmux from launching inside an existing tmux session, which would nest them.


~/.tmux.conf

A minimal config that most people find immediately useful:

# Start window and pane numbering at 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1

# Enable mouse: click to focus panes, drag to resize
set -g mouse on

# Increase scrollback
set -g history-limit 10000

# Status bar: show session name on the left, time on the right
set -g status-left "[#S] "
set -g status-right "%H:%M"
Enter fullscreen mode Exit fullscreen mode

Reload the config without restarting:

Ctrl+B  :source-file ~/.tmux.conf
Enter fullscreen mode Exit fullscreen mode

Mouse support is the single option worth enabling immediately if you are used to a GUI terminal. It makes pane navigation and resizing click-based while you build up the keyboard shortcuts.


Found this useful? SysEmperor has more Linux tutorials and free developer tools — including a Cron Visual Editor, fstab Editor, and a growing library of downloadable AI skills at sysemperor.com.

Top comments (0)