tmux / screen
tmux is a terminal multiplexer — sessions, windows, and panes that survive disconnects. Two reasons it is indispensable on remote machines: you ssh in, attach to a session, work, disconnect, come back tomorrow, attach, and your shells are exactly where you left them. Plus split panes for tail -f next to your editor.
Sessions, panes, scripted layouts, keybindings
EXAMPLE
# 1) Start a named session tmux new -s work # 2) Common keys (prefix = Ctrl+B by default) # prefix d detach session (work keeps running) # prefix c new window # prefix , rename window # prefix 0..9 switch to window N # prefix \" split horizontal # prefix % split vertical # prefix arrow move between panes # prefix z zoom current pane (toggle) # prefix [ enter copy mode (q to exit) # prefix ] paste # 3) Reattach later — from a fresh ssh, the same shells are running tmux ls # work: 2 windows (created Wed Jun 11 09:01) (attached) tmux attach -t work # 4) Kill a runaway session tmux kill-session -t scratch # 5) Scripted layout: start a four-pane dev dashboard from CI or shell rc tmux new -d -s dev 'top' tmux split-window -h -t dev:0 'tail -F /var/log/syslog' tmux split-window -v -t dev:0.0 'cd ~/app && npm run dev' tmux split-window -v -t dev:0.1 'cd ~/app && npm test -- --watch' tmux select-layout -t dev:0 tiled tmux attach -t dev # 6) Persist sensible keybindings — ~/.tmux.conf cat <<'EOF' >> ~/.tmux.conf set -g mouse on set -g history-limit 100000 set -g base-index 1 set -g renumber-windows on # Use Ctrl+A instead of Ctrl+B (gnu-screen style) unbind C-b set -g prefix C-a bind C-a send-prefix # Quick split shortcuts bind | split-window -h bind - split-window -v # Reload config without restarting tmux bind r source-file ~/.tmux.conf \; display 'tmux reloaded' EOF tmux source-file ~/.tmux.conf # 7) Pair-programming: two devs attach to the same session ssh alice@host -> tmux new -s pair ssh bob@host -> tmux attach -t pair # both see and type the same shell
Why it matters
tmux + ssh beats nohup, screen, and \"leave my laptop open\" for any long-running remote work. The mental model: sessions are workspaces, windows are tabs, panes are splits. Once it clicks, you stop closing terminals and start detaching them.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…