Security

Essential Commands And Quick References

Running parallel processes on a graphical user interface (GUI) usually requires tabbed terminals. But what if you could only work with command-line interfaces (CLI)? The answer is Tmux, which is short for “terminal multiplexer.”

Better still, in Tmux, you can detach from a session without losing its state and later return to it by re-attaching it. This hands-free functionality is helpful when you, say, need to make multiple SSH connections because, by default, an SSH session occupies the entire CLI, hindering you from working on other tasks in tandem.

A PDF download of this cheat sheet is available here.

Tmux Cheat Sheet Search

Search our Tmux cheat sheet to find the right cheat for the term you’re looking for. Simply enter the term in the search bar and you’ll receive the matching cheats available.

Install Tmux

Tmux is available for Linux and macOS. As for Windows, you can run Tmux via the Linux Subsystem feature by following the procedures here if you’re using Windows 10 build 14361 or above. This article assumes you are using either Linux or macOS.

Command Description
# Homebrew
brew install tmux
Install on macOS
# Ubuntu / Debian *
sudo apt-get update
sudo apt-get install tmux
# Fedora
sudo
dnf -y install tmux
# CentOS
sudo
yum -y install tmux
Install on Linux
(*Depending on Linux distribution, you may need to replace apt-get with apt.)

Tmux Terms

Familiarize yourself with them as they often appear in Tmux-related discussions.

Term Description
Pane An open command prompt (known as “pseudo-terminal”), which may occupy the entire screen or appear horizontally/vertically stacked
Window A single/split view of open panes occupying the screen:

Split windows

Session A single collection of pseudo-terminals under the management of Tmux. Once you kill the last session, Tmux exits. Each session is persistent and will survive accidental disconnection (such as SSH connection timeout) or intentional detaching by the user.
In the example above, the session comprises panes 0:bash, 1:bash, and 2:bash. The current pane is 2:bash, marked by an asterisk *. Here, the cursor is active, and you can type into the pane. The other pane in the same window is 1:bash, marked by a hyphen -.
Client The background process displaying your session
Server A single server manages all open sessions. Servers and clients are separate processes that communicate through a socket in /tmp.

Tmux Commands

You may run Tmux commands by name from the CLI, such as tmux starts a new session. When you start Tmux, it creates a new single-window session and displays it on the screen.

A status line at the bottom shows current session information and is used to enter interactive commands prefixed by the trigger key combination Ctrl+b (Linux) or control+b (macOS). This trigger tells Tmux to watch out for keystrokes of interest.

Ctrl+b alone applies to short commands of one or two keys. Ctrl+b followed by the colon character (:) brings up a prompt for you to issue specific commands, after which you press Enter for execution.

Other Links You Might Like:

Tmux Shortcuts

Run the following from the CLI:

Command Description
tmux Launch Tmux
tmux -V Check Tmux version
tmux list-keys | less List all commands
tmux ls Show all sessions
tmux info Show every session, window, and pane
tmux a (Re)attach to the most recently created session
man tmux Display full manual of Tmux

Run these commands inside a Tmux session:

Command Description
q After execution of a command yields a display, close the display. For example, Ctrl+b+? brings up a list, and a single q keypress closes the list.
Ctrl+b
Send to Tmux instead of shell CLI. For each of the following items, replace with the given key.
Ctrl+l Clear console contents (the “l” is “L” in small caps)
General
?
:list-keys
List all commands
: Enter command mode (display prompt for detailed Tmux commands)
t Show computer time
Windows
c Create new window
, Rename current window
p Navigate to previous window
n Navigate to next window
w List windows (which you may select and expand / collapse with arrow keys)
Panes
% Split vertically
" Split horizontally
(right arrow key) Switch to right pane
(left arrow key) Switch to left pane
(up arrow key) Switch to upper pane
(down arrow key) Switch to lower pane
Sessions
d Detach from session

Scroll down for specific commands in detail.

Tmux Sessions

Create new session

Command Description
tmux
tmux new
tmux new-session
Create new session from CLI
Ctrl+b :new Create new session from inside Tmux
tmux new -s sess0 Create new session named sess0
Ctrl+b :new sess0 Create new session sess0 from inside Tmux

List all sessions

Command Description
tmux ls
tmux list-sessions
Show all sessions
Ctrl+b s Show all sessions from inside Tmux

Operations on sessions

Command Description
tmux a
tmux at
tmux attach
tmux attach-session
Attach to the most recently created session
tmux a -t s0 Attach to session s0
Ctrl+b
Rename session
Detach from session
Session and window preview
Move to previous session
Move to next session

Terminate (kill) sessions

Command Description
tmux kill-ses
tmux kill-session
Kill last active session
tmux kill-ses -t s0 Kill session named s0
tmux kill-ses -a Kill all sessions except the current one
tmux kill-ses -a -t s0 Kill all sessions except s0

OTHER CHEAT SHEETS YOU MAY LIKE:

Tmux Windows

Command Description
tmux new -s s1 -n w2 Create new session s1 and window w2
Ctrl+b
c Create new window
, Rename active window
& Close active window (Tmux may prompt you to confirm your action with y/n)
p Navigate to previous window
n Navigate to next window
w List windows (which you may select and expand / collapse with arrow keys)
:swapw -s 0 -t 2 Swap windows 0 and 2(swapw is short for swap-window)
:swapw -t -1 Move active window to the left by one position

Tmux Command Generator

Say goodbye to the hassle of trying to remember the exact syntax for your Tmux commands! With our Tmux Command Generator, you can simply say what you need Tmux to do, and we will generate the command for you.

Tmux Panes

Command Description
Ctrl+b
q Show pane numbers:

Numbered panes in Tmux

q 0 … 9 Switch to pane by number
o Go to next pane
z Zoom in/out of pane
! Convert pane into new window
% Split vertically
Split horizontally
Switch to right pane
Switch to left pane
Switch to upper pane
Switch to lower pane
; Toggle last active pane
[spacebar] Toggle between pane layouts
{ Move current pane leftward
} Move current pane rightward
x Close current pane
:setw synchronize-panes Toggle synchronize-panes (the ability to send the same command to all panes at once)

Synchronize panes

:resize-pane -L 5 Move the boundary of the pane leftwards by 5 lines.
Direction flags:
-U upwards
-D downwards
-L leftwards
-R rightwards
M #
M: meta key; ALT for Linux, ESC for macOS#: 1, 2, 3, 4, 5
Splitting panes in a designated form:
#=1: uniform vertical split
#=2: uniform horizontal split
#=3: horizontal split, main pane on top, others on bottom, vertically split, all same width
#=4: vertical split, main pane left, others right, horizontally split, all same height
#=5: tile, new panes on bottom, same height before same width

Tmux Copy Mode

You can copy and paste text content in Tmux under Copy Mode. The buffer in Tmux is its clipboard and buffer_0, buffer_1, etc. correspond to clipboard items copied from a Tmux session.

Command Description
Ctrl+b :setw -g mode-keys vi Use vi keys in the buffer (vi: vim editor)
Ctrl+b [ Enter copy mode
Scroll up
Scroll down
q Quit copy mode
0 Go to beginning of line
$ Go to end of line
g Go to first line
G Go to last line
h Move cursor left
j Move cursor down
k Move cursor up
l Move cursor right
b Traverse text content backward, cursor on first character of each word
e Traverse text content forward, cursor on last character of each word
w Traverse text content one word at a time
/ Search forward
? Search backward
n Next keyword occurrence
N Previous keyword occurrence
[Spacebar] Begin selection
[Enter] Copy selection
ESC Clear selection
Ctrl+b ] Paste selection
Ctrl+b :show-buffer Display buffer_0 contents
Ctrl+b :capture-pane Copy whole visible contents of the pane to a buffer
Ctrl+b :list-buffers Show all buffers
Ctrl+b :choose-buffer Show all buffers and paste selected
Ctrl+b :save-buffer buf.txt Save buffer contents to buf.txt
Ctrl+b :delete-buffer -b 1 Delete buffer_1

Tmux Configuration

You can configure Tmux via the ~/.tmux.conf file. If it doesn’t exist, create it:

$ touch ~/.tmux.conf

To reload Tmux with the new settings:

$ tmux source-file ~/.tmux.conf

Custom Keystrokes

Add these commands to ~/.tmux.conf to modify Tmux function keys. Each command spans two lines. The unbind command deactivates the default key combination.

Command Description
unbind '"'
bind - split-window -v
Change key combination to split window into two horizontal panes: Replace default Ctrl+b ” with Ctrl+b – (hyphen) 
unbind %
bind | split-window -h
Change key combination to split window into two vertical panes: Replace default Ctrl+b % with Ctrl+b | (pipe) 
unbind C-b
set -g prefix C-a
Replace trigger key combination Ctrl+b with Ctrl+a

Making Tmux Copy Mode to default to vi keys

Command Description
setw -g mode-keys vi Use vi keys in the buffer

Customization

The following commands are for customizing the status bar at the bottom of a Tmux window:

Command Description
set -g status-justify [left|centre|right] Aligns the names of Tmux windows left/center/right
set -g status-left '...' Replaces name of current session with ‘…’  in status bar
setw -g
window-status-format
`#[fg=white,bg=black]#I`
Formats the window names as follows:
Formatted status bar
Default window formatting:
Default status bar
Variables:
#I: window index
#S: session name
#W: window name

For detailed formatting instructions: man tmux > /STYLES > keep pressing “n” key until you reach the section titled “STYLES”.

To reset Tmux to default settings, delete all lines in ~/.tmux.conf and run tmux kill-server. Close any running CLI terminals, reopen the terminal and start Tmux again.

Frequently Asked Questions

Guarantee Your Cyber Security Career with the StationX Master’s Program!

Get real work experience and a job guarantee in the StationX Master’s Program. Dive into tailored training, mentorship, and community support that accelerates your career.

  • Job Guarantee & Real Work Experience: Launch your cybersecurity career with guaranteed placement and hands-on experience within our Master’s Program.
  • 30,000+ Courses and Labs: Hands-on, comprehensive training covering all the skills you need to excel in any role in the field.
  • Pass Certification Exams: Resources and exam simulations that help you succeed with confidence.
  • Mentorship and Career Coaching: Personalized advice, resume help, and interview coaching to boost your career.
  • Community Access: Engage with a thriving community of peers and professionals for ongoing support.
  • Advanced Training for Real-World Skills: Courses and simulations designed for real job scenarios.
  • Exclusive Events and Networking: Join events and exclusive networking opportunities to expand your connections.

TAKE THE NEXT STEP IN YOUR CAREER TODAY!


  • Cassandra Lee



    Cassandra is a writer, artist, musician, and technologist who makes connections across disciplines: cyber security, writing/journalism, art/design, music, mathematics, technology, education, psychology, and more. She’s been a vocal advocate for girls and women in STEM since the 2010s, having written for Huffington Post, International Mathematical Olympiad 2016, and Ada Lovelace Day, and she’s honored to join StationX. You can find Cassandra on LinkedIn and Linktree.


Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button