
TMUX is an easy to use Terminal Multiplexer where users can split the Terminal CLI (Command Line Interface) into multiple mini Terminals. Here’s a TMUX Cheat Sheet with essential tmux commands:
Installing tmux
The following command installs tmux from the snap repositories.
sudo snap install tmux
In the case that snap is is not installed on the ubuntu server type in:
sudo apt install snapd
Starting & Exiting Tmux
tmux– Start a new tmux sessiontmux new -s <name>– Start a new named sessiontmux attach -t <name>– Attach to an existing sessiontmux detach(Ctrl-b d) – Detach from the current sessiontmux list-sessions– List all active sessionstmux kill-session -t <name>– Kill a specific sessiontmux kill-server– Kill all sessions and exit tmux
Ctrl – b commands:
When Ctrl + b is used in a command that means that the user must press Ctrl + b then release the key combo before continuing with the rest of the command. An example would be to split the Terminal vertically the user would need to press Ctrl + b, release then press shift + 5.
Pane Management
Ctrl-b %– Split the window verticallyCtrl-b "– Split the window horizontallyCtrl-b o– Switch between panesCtrl-b ;– Move to the last active paneCtrl-b x– Close the current paneCtrl-b z– Toggle pane zoomCtrl-b {– Move pane leftCtrl-b }– Move pane right
Window Management
Ctrl-b c– Create a new windowCtrl-b n– Switch to the next windowCtrl-b p– Switch to the previous windowCtrl-b w– Choose a window interactivelyCtrl-b ,– Rename the current windowCtrl-b &– Close the current window
Session Management
tmux rename-session -t <old_name> <new_name>– Rename a sessiontmux switch -t <name>– Switch to a different sessiontmux detach-client -s <name>– Detach a client from a session
Scrolling & Copy-Paste
Ctrl-b [– Enter scroll mode (use arrow keys orPgUp/PgDn)Space– Start selectionEnter– Copy selectionCtrl-b ]– Paste
Resizing Panes
When resizing Terminal panes, the easiest way is to press and HOLD the Ctrl + B and then use the arrow keys on the keyboard to resize the current window as needed. This is a much easier way than typing in the command.
Ctrl-b : resize-pane -D 5– Resize pane downCtrl-b : resize-pane -U 5– Resize pane upCtrl-b : resize-pane -L 5– Resize pane leftCtrl-b : resize-pane -R 5– Resize pane right
Personal TMUX Preference on sign-in.
You can add and modify a tmux script so that one pane starts btop (a system monitor) and another starts ranger (a file manager). Here’s how:
tmux Script
#!/bin/bash
# Start a new tmux session named 'mysession' (detached mode)
tmux new-session -d -s mysession
# Split the window vertically (equivalent to Ctrl + b %)
tmux split-window -h -t mysession
# Split the first pane horizontally (equivalent to Ctrl + b ")
tmux split-window -v -t mysession:0.0
# Start 'btop' in the top-left pane
tmux send-keys -t mysession:0.0 'btop' C-m
# Start 'ranger' in the bottom-left pane
tmux send-keys -t mysession:0.1 'ranger' C-m
# Attach to the tmux session
tmux attach -t mysession
What This Script Does
- Creates a tmux session named
mysession. - Splits the screen vertically (
Ctrl + b %). - Splits the left pane horizontally (
Ctrl + b "), resulting in three panes:- Top-right pane → Runs
btop. - Bottom-right pane → Runs
ranger. - Left pane → Remains free (you can use it for other commands).
- Top-right pane → Runs
- Sends commands to start
btopandrangerin their respective panes. - Attaches to the session so you can interact with it immediately.
Create Script File
sudo nano ~/tmux-script.sh
Enter in the script above and make changes to desired preference.
Save by pressing ctrl + O
Exit by pressing ctrl + X
Run the Script
To run the script simply type in ~/tmux-script.sh
Optional: Make it Run on Login
If you want tmux to start automatically when you log in:
sudo nano ~/.bashrc: nano ~/.bashrc
Add the following at the bottom: if [[ -z "$TMUX" ]]; then ~/start_tmux.sh fi
Save the changes by pressing ctrl +
Exit with ctrl + x
