Using Terminal Multiplexers Like Screen and Tmux: A Practical Guide
Terminal multiplexers like screen and tmux enable persistent terminal sessions that survive SSH disconnections, allowing you to detach from remote work and re-attach later without interrupting running processes.
The jlevy/the-art-of-command-line repository provides battle-tested recommendations for command-line productivity, including specific guidance on using terminal multiplexers like screen and tmux to manage long-running remote sessions. According to the source documentation at line 171 of README.md, these tools are essential for maintaining work continuity over unstable SSH connections.
The Multiplexers Recommendation in the-art-of-command-line
In the Multiplexers subsection of the master README, the repository explicitly recommends using screen or tmux to multiplex terminal sessions. The documentation states:
"Use
screenortmuxto multiplex the screen, especially useful on remote ssh sessions and to detach and re‑attach to a session.byobucan enhance screen or tmux …"
This guidance appears at line 171 of README.md and reflects the repository's focus on practical, immediately applicable command-line techniques. Because the repository is documentation-centric rather than code-centric, the recommendation serves as a curated pointer to these essential system utilities.
GNU Screen Basics
GNU Screen remains the classic choice for terminal multiplexing, providing session persistence since 1987. The tool creates virtual terminals that persist independently of your SSH connection.
To start and manage a screen session:
# Start a new session named "work"
screen -S work
# Detach from the session (leave it running)
Ctrl-a d
# List existing sessions
screen -ls
# Re-attach to the "work" session
screen -r work
Screen uses the Ctrl-a prefix for all command sequences, making it distinct from tmux's key bindings.
Tmux Session Management
Tmux (Terminal Multiplexer) offers modern features including vertical/horizontal pane splitting, customizable status bars, and scriptable configuration. It has largely superseded screen in contemporary workflows.
Basic tmux workflow commands:
# Start a new session named "dev"
tmux new -s dev
# Detach from the session (leave it running)
Ctrl-b d
# List existing sessions
tmux ls
# Re-attach to the "dev" session
tmux attach -t dev
Tmux uses Ctrl-b as its default prefix key and provides more intuitive command syntax for session naming and management compared to screen.
Enhancing with Byobu
Byobu functions as a configuration layer and wrapper that enhances either screen or tmux with status notifications, window labels, and the F-key menu system. The the-art-of-command-line README specifically mentions byobu as an enhancement option.
Installation and basic usage:
# Install Byobu (Debian/Ubuntu)
sudo apt install byobu
# Launch Byobu (uses tmux by default)
byobu
# Detach and re-attach using the same shortcuts as tmux
Ctrl-a d # detach
byobu-select-session # re-attach
Byobu abstracts the underlying multiplexer, allowing you to switch between screen and tmux backends while maintaining a consistent interface.
Summary
- Terminal multiplexers like screen and tmux solve the problem of lost work during SSH disconnections by maintaining persistent server-side sessions.
- The
jlevy/the-art-of-command-linerepository explicitly recommends these tools at line 171 ofREADME.mdfor remote SSH workflows. - Screen uses
Ctrl-aprefixes and the-Sflag for naming sessions, while tmux usesCtrl-bprefixes and thenew -ssyntax. - Byobu provides an enhanced interface layer atop either multiplexer, adding system status indicators and simplified key bindings.
- All three tools support the core workflow: create, detach, list, and re-attach to sessions.
Frequently Asked Questions
What is the difference between screen and tmux?
Tmux offers more modern features such as easier pane splitting, client-server architecture for better performance, and a cleaner configuration syntax, while screen provides wider legacy compatibility across older Unix systems. Both support the essential detach/reattach functionality, but tmux has become the default recommendation for new users due to its active development and superior window management.
How do I re-attach to a detached session after losing SSH connection?
For screen, use screen -r <session-name> or screen -r if only one session exists. For tmux, use tmux attach -t <session-name> or simply tmux attach if targeting the most recent session. Both commands reconnect you to the exact terminal state before disconnection, including running processes and command history.
Is byobu a separate multiplexer or a wrapper around screen and tmux?
Byobu is a wrapper and configuration framework that enhances either screen or tmux with additional features like system status bars, window labels, and F-key menus. It defaults to using tmux as its backend but can be configured to use screen, providing a consistent interface regardless of the underlying multiplexer technology.
When should I use terminal multiplexers instead of background processes?
Use terminal multiplexers when you need interactive access to long-running processes, want to maintain multiple terminal contexts simultaneously, or require persistence across SSH disconnections. Background processes with nohup work for non-interactive tasks, but multiplexers preserve your full terminal environment, scrollback history, and allow real-time interaction with running programs.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →