#tmux #terminal #sessions #ssh #shel #bash #fish
### **Tmux: Terminal Multiplexer Guide**
Tmux is a **powerful terminal multiplexer** that allows multiple sessions, windows, and panes within a single terminal window.
---
## **1. Install and Start Tmux**
### **Install Tmux (Ubuntu)**
`sudo apt install tmux -y`
### **Start a New Tmux Session**
`tmux`
This starts a new **unnamed** session.
---
## **2. Sessions**
### **Create and Manage Sessions**
| **Command** | **Description** |
| ------------------------------------------------ | ------------------------------------------------- |
| `tmux new -s mysession`<br>``tmux -A mysession`` | Create a new session or attach to an existing one |
| `tmux new -s mysession` | Start a new session with a name |
| `tmux ls` | List all running Tmux sessions |
| `tmux a` | Attach to the most recent session |
| `tmux a -t mysession` | Attach to a specific session |
| `tmux kill-session -t mysession` | Kill a specific session |
| `tmux kill-session -a` | Kill all sessions except the current one |
### **Detach and Reattach**
- **Detach from a session**:
`CTRL + B`, then `D`
- **Reattach to a session**:
`tmux attach`
---
## **3. Windows**
Windows in Tmux are like tabs in a terminal.
| **Command** | **Description** |
| --------------------- | ---------------------------- |
| `CTRL + B` then `C` | Create a new window |
| `CTRL + B` then `,` | Rename the current window |
| `CTRL + B` then `&` | Close the current window |
| `CTRL + B` then `W` | List all windows |
| `CTRL + B` then `P` | Go to the previous window |
| `CTRL + B` then `N` | Go to the next window |
| `CTRL + B` then `0-9` | Switch to a window by number |
---
## **4. Panes**
Panes split a window into multiple sections.
### **Create Panes**
| **Command** | **Description** |
| ------------------- | -------------------------------------- |
| `CTRL + B` then `%` | Split window vertically (left/right) |
| `CTRL + B` then `"` | Split window horizontally (top/bottom) |
### **Navigate Between Panes**
| **Command** | **Description** |
| ---------------------------- | -------------------------------- |
| `CTRL + B` then `Arrow Keys` | Move between panes |
| `CTRL + B` then `;` | Toggle between last active panes |
### **Resize Panes**
| **Command** | **Description** |
| ----------------------------------- | ------------------ |
| `CTRL + B` then `CTRL + Arrow Keys` | Resize pane |
| `CTRL + B` then `+` | Increase pane size |
| `CTRL + B` then `-` | Decrease pane size |
### **Close Panes**
| **Command** | **Description** |
| ------------------- | ---------------------- |
| `CTRL + B` then `X` | Close the current pane |
---
## **5. Copy Mode**
Tmux allows you to **copy and paste** inside sessions.
| **Command** | **Description** |
| ---------------------- | -------------------- |
| `CTRL + B` then `[` | Enter Copy Mode |
| `CTRL + B` then `PgUp` | Scroll up one page |
| `Spacebar` | Start selection |
| `Enter` | Copy selection |
| `CTRL + B` then `]` | Paste copied content |
---
## **6. Miscellaneous Commands**
| **Command** | **Description** |
| -------------------- | ----------------------- |
| `CTRL + B` then `:` | Enter Tmux command mode |
| `tmux list-keys` | List all key bindings |
| `tmux list-sessions` | Show all Tmux sessions |
---
## **7. Enable Mouse Support**
Enable mouse scrolling and clicking inside Tmux:
`tmux set -g mouse on`
---
### **🚀 Now you can manage multiple terminal sessions efficiently using Tmux!** ✅
[[Terminal, beautify your terminal with oh-my-posh]]
[[Chris Titus' LinUtil and the nice bash prompt]]
[NetworkChuck](https://www.youtube.com/watch?v=nTqu6w2wc68)
[TMUX CheatSheet](https://tmuxcheatsheet.com/)