Linux Comm Tmux
[ Linux Command Encyclopaedia](#)\n\n* * *\n\ntmux (Terminal Multiplexer) is a terminal multiplexing tool that allows you to create multiple virtual terminal sessions within a single terminal window and keep these sessions running in the background. Compared to directly using the terminal, tmux provides more powerful session management features.\n\n**Core Advantages**:\n\n* Session Persistence: Sessions remain on the server even when the network disconnects\n* Multi-window/Pane Management: Efficiently organize multiple work environments\n* Session Sharing: Multiple users can connect to the same session simultaneously\n\n* * *\n\n## Install tmux\n\nIn most Linux distributions, tmux can be easily installed via the package manager:\n\n## Example\n\n# Ubuntu/Debian\n\nsudo apt-get install tmux\n\n# CentOS/RHEL\n\nsudo yum install tmux\n\n# macOS (using Homebrew)\n\n brew install tmux\n\nAfter installation, you can start a new session by typing the `tmux` command.\n\n* * *\n\n## Basic Concepts\n\n### Session\n\nA tmux session is an independent running environment that can contain multiple windows. Even when you disconnect, the session continues to run in the background.\n\n### Window\n\nEach session can contain multiple windows, similar to tabs in a browser.\n\n### Pane\n\nEach window can be split into multiple panes, allowing you to view and operate multiple terminals simultaneously.\n\n* * *\n\n## Common Commands and Shortcuts\n\nAll tmux operations require first pressing the prefix key (default is `Ctrl+b`), then entering the command key.\n\n### Session Management\n\n| Command/Shortcut | Description |\n| --- | --- |\n| `tmux new -s ` | Create a new session named name |\n| `Ctrl+b d` | Detach from current session (session continues running in background) |\n| `tmux ls` | List all sessions |\n| `tmux attach -t ` | Reconnect to the specified session |\n| `Ctrl+b $` | Rename current session |\n| `Ctrl+b s` | Switch sessions |\n\n### Window Management\n\n| Command/Shortcut | Description |\n| --- | --- |\n| `Ctrl+b c` | Create new window |\n| `Ctrl+b &` | Close current window |\n| `Ctrl+b n` | Switch to next window |\n| `Ctrl+b p` | Switch to previous window |\n| `Ctrl+b ` | Switch to window with specified number |\n| `Ctrl+b ,` | Rename current window |\n\n### Pane Management\n\n| Command/Shortcut | Description |\n| --- | --- |\n| `Ctrl+b %` | Split current pane vertically |\n| `Ctrl+b "` | Split current pane horizontally |\n| `Ctrl+b ` | Move focus between panes |\n| `Ctrl+b x` | Close current pane |\n| `Ctrl+b z` | Maximize/restore current pane |\n| `Ctrl+b Space` | Toggle pane layout |\n\n* * *\n\n## Configure tmux\n\nThe tmux configuration file is located at `~/.tmux.conf`. Here are some common configuration examples:\n\n## Example\n\n# Set prefix key to Ctrl+a (easier to press than default Ctrl+b)\n\n unbind C-b\n\nset-g prefix C-a\n\nbind C-a send-prefix\n\n# Enable mouse support (can use mouse to click to switch panes/windows)\n\nset-g mouse on\n\n# Set status bar colors\n\nset-g status-bg black\n\nset-g status-fg white\n\n# Set pane border colors\n\nset-g pane-border-style fg=green\n\nset-g pane-active-border-style fg=red\n\n# Set windows to start numbering from 1 (default is 0)\n\nset-g base-index 1\n\n setw -g pane-base-index 1\n\nAfter modifying the configuration, you can press `Ctrl+b :` and then input `source-file ~/.tmux.conf` to reload the configuration.\n\n* * *\n\n## Practical Tips\n\n### 1. Session Restoration\n\nYou can restore tmux sessions even after server restarts:\n\n## Example\n\n# Install plugin\n\ngit clone https://github.com/tmux-plugins/tmux-resurrect ~/clone/path\n\n# Add to .tmux.conf\n\nset -g @plugin 'tmux-plugins/tmux-resurrect'\n\n### 2. Copy Mode\n\n* `Ctrl+b [` to enter copy mode\n* Use arrow keys to move cursor\n* Press space to start selection, enter to copy\n* `Ctrl+b ]` to paste\n\n### 3. Synchronize Input\n\nEnter the same command in multiple panes simultaneously:\n\n## Example\n\n# Enter sync mode\n\n Ctrl+b :setw synchronize-panes on\n\n# Turn off sync mode\n\n Ctrl+b :setw synchronize-panes off\n\n### 4. Quickly Create Development Environment\n\n## Example\n\n# Create a development session with 3 panes\n\n tmux new -s dev -d\n\n tmux send-keys -t dev:0"vim" C-m\n\n tmux split-window -h-t dev:0\n\n tmux split-window -v-t dev:0.1\n\n tmux attach -t dev\n\n* * *\n\n## Common Problems and Solutions\n\n### 1. Cannot Use Mouse Scrolling\n\nAdd to `.tmux.conf`:\n\nset -g terminal-overrides 'xterm*:smcup@:rmcup@'\n### 2. Colors Not Displaying Properly\n\nEnsure your terminal supports 256 colors, add:\n\nset -g default-terminal "screen-256color"\n### 3. Shortcut Conflicts\n\nIf certain shortcuts conflict with your other tools, you can rebind them in the configuration file.\n\n* * *\n\n## Learning Path Suggestions\n\n1. First master basic session management (create, detach, reconnect)\n2. Practice basic window and pane operations\n3. Familiarize yourself with common shortcuts\n4. Customize configuration based on your needs\n5. Explore advanced features and plugins\n\nThrough continuous practice, you will gradually discover how tmux can greatly improve your terminal work efficiency.\n\n* * Linux Command Encyclopaedia](#)
YouTip