Problem Statement
Explain screen and tmux for terminal multiplexing. What are their key features and use cases?
Explanation
Screen and tmux are terminal multiplexers allowing multiple terminal sessions in one window, with the crucial ability to detach sessions that continue running and reattach later. This is invaluable for long-running tasks on remote servers - if SSH disconnects, your processes keep running and you can reattach to see their status.
Screen basics: start with screen, detach with Ctrl+A then D, list sessions with screen -ls, reattach with screen -r. Create named sessions: screen -S sessionname. Within screen, Ctrl+A then C creates new window, Ctrl+A then N cycles windows, Ctrl+A then number switches to specific window. Split screen: Ctrl+A then S (horizontal) or Ctrl+A then | (vertical).
Tmux is more modern with similar functionality: start with tmux, detach with Ctrl+B then D, list with tmux ls, attach with tmux attach -t sessionname. Create panes: Ctrl+B then % (vertical split) or Ctrl+B then " (horizontal split). Navigate panes: Ctrl+B then arrow keys. Tmux has better pane management, scripting support, and status bars.
Use cases: running builds or deployments that take hours on remote servers, maintaining IRC or chat sessions, pair programming with shared sessions (screen -x or tmux attach), monitoring logs while working in another window, and ensuring work isn't lost during network interruptions. Essential tools for anyone working with remote Linux servers.
Practice Sets
This question appears in the following practice sets:
