tmux (Terminal Multiplexer)
tmux is a terminal multiplexer, a command-line tool used to manage multiple terminal sessions within a single window. It's popular in Unix-like operating systems, such as Linux and macOS.
Purpose
-
Multiple Sessions:
tmuxallows users to create, access, and control several terminal sessions from a single screen. This feature is particularly useful for working with multiple command-line applications simultaneously. -
Session Detachment and Reattachment: Users can detach from a session and leave it running in the background, then later reattach to it. This is extremely useful for long-running processes, especially when connecting via SSH (Secure Shell), as the process continues even if the connection is lost.
-
Window Management: Within each session,
tmuxallows for the creation of multiple windows, enabling users to organize their work more efficiently. -
Pane Splitting: Users can split windows into panes, allowing for side-by-side command-line work. This feature is helpful for comparing outputs, monitoring multiple streams of data, or multitasking.
-
Scriptability:
tmuxsupports scripting, which allows automating and customizing the work environment, such as setting up a predefined layout of windows and panes. -
Persistence: Sessions in
tmuxare persistent, meaning they survive user logouts or network disconnections, which is particularly useful for remote work.
How it Works
- Starting tmux: A user enters
tmuxin the command line to start a new session. - Navigating Sessions: Within
tmux, users can create new sessions, switch between them, or close them as needed. - Windows and Panes: Users can open multiple windows within a session and split these windows into panes.
- Detach/Attach: Users can detach from a session and later reattach to it. This maintains the state of the session as it was left.
Applications
-
Remote Work: It's widely used by system administrators and developers who connect to remote servers via SSH, as it ensures continuity of work irrespective of the network connection.
-
Development: Developers use
tmuxfor an integrated development environment in the terminal, managing editors, servers, and logs in one place. -
Command-Line Tasks: Ideal for managing multiple command-line tasks simultaneously, monitoring, and comparing outputs in real-time.
Command Examples
Starting and Managing Sessions
- Start new session:
tmuxortmux new -s session_name - Attach to session:
tmux attach -t session_name - Detach from session:
Ctrl+bthend - List sessions:
tmux ls - Kill session:
tmux kill-session -t session_name
Managing Windows
- Create window:
Ctrl+bthenc - Switch to window:
Ctrl+bthen0...9 - Rename current window:
Ctrl+bthen, - Close current window:
Ctrl+bthen&
Managing Panes
- Split pane horizontally:
Ctrl+bthen" - Split pane vertically:
Ctrl+bthen% - Navigate between panes:
Ctrl+bthen arrow keys - Resize panes:
Ctrl+bthenCtrl+ arrow keys - Close current pane:
Ctrl+bthenx
Miscellaneous
- Enter scroll mode:
Ctrl+bthen[, navigate using arrow keys,qto exit - Capture pane content to file:
Ctrl+bthen:capture-pane -S -100then:save-buffer filename.txt - Reload config file:
tmux source-file ~/.tmux.conf - Show help:
Ctrl+bthen?
Conclusion
tmux is a powerful tool for enhancing productivity at the command line. Its ability to manage multiple terminal sessions efficiently, maintain persistence, and offer flexible window and pane management makes it a go-to tool for developers, system administrators, and power users working in Unix-like environments.