Tmux revolutionizes terminal productivity by enabling multiple sessions, windows, and panes. This comprehensive cheat sheet will transform you from a tmux novice to a command-line multitasking pro.
Key Tmux Commands for Efficiency
- Create session:
tmux new -s session_name
- List sessions:
tmux ls
- Attach to session:
tmux attach -t session_name
- Detach from session:
Ctrl-b d
- Kill session:
tmux kill-session -t session_name
- Kill tmux server:
tmux kill-server
Creating a Powerful Tmux Session
Launch a new tmux session for a web development project:
tmux new -s web_dev
This creates a session named “web_dev”. Once inside:
- Split the window vertically:
Ctrl-b %
- Split the right pane horizontally:
Ctrl-b "
- Navigate to your project directory:
cd ~/projects/my_website
- In the top-right pane, start your development server:
npm start
- In the bottom-right pane, open your text editor:
vim index.html
You now have a terminal for commands, a pane showing your running server, and a pane for editing code.
Exiting a Tmux Session Gracefully
To leave your session running in the background:
Ctrl-b d
This detaches from the session, leaving your development environment intact for later.
Listing and Managing Existing Sessions
View all active tmux sessions:
tmux ls
Output might look like:
web_dev: 3 windows (created Tue Sep 10 14:30:22 2024)
data_analysis: 2 windows (created Tue Sep 10 09:15:10 2024)
Deleting Tmux Sessions
From Inside Tmux
To kill the current session from within tmux:
- Enter command mode:
Ctrl-b :
- Type the command:
kill-session
- Press Enter
From Outside Tmux
To remove a specific session, e.g., “data_analysis”:
tmux kill-session -t data_analysis
Re-attaching to a Tmux Session
Return to your web development environment:
tmux attach -t web_dev
You’ll find your panes and processes exactly as you left them.
Killing the Entire Tmux Server
For a fresh start, terminate all tmux sessions and the server:
tmux kill-server
Caution: This closes all tmux sessions. Use it when you’re sure you don’t need any running sessions.
Advanced Tmux Usage
- Create a new window:
Ctrl-b c
- Switch to next window:
Ctrl-b n
- Rename current window:
Ctrl-b ,
- Enter copy mode (for scrolling):
Ctrl-b [
- Start selection in copy mode:
Space
- Copy selection:
Enter
- Paste copied text:
Ctrl-b ]
Master these commands, and you’ll dramatically enhance your terminal workflow, juggling multiple projects with ease.