Emergency server help: get in touch

Terminal Shortcuts Cheat Sheet: Bash, Zsh and tmux

Keyboard shortcuts and shell features for Bash and Zsh: line editing, history, job control, redirection, globbing, tmux and terminal apps.

Published 8 min read

Short answer: The shortcuts that save the most time in Bash and Zsh are Ctrl+A and Ctrl+E to jump along the line, and Ctrl+U, Ctrl+K and Ctrl+W to delete. Ctrl+R searches history, Alt+. inserts the last argument and !! repeats the last command. For jobs, Ctrl+Z suspends and bg resumes in the background. Learn redirection (2>&1, <<<, <(...)), brace expansion and tmux for sessions that survive a dropped SSH connection.

The examples in this terminal cheat sheet were run with GNU Bash 5.2.21 and tmux 3.4 on 9 October 2026. Readline bindings were read from bind -p, and the tmux keys from tmux list-keys. Zsh, screen and the terminal apps were not available for testing, so those rows were checked against their documentation.

Editing the command line

Bash uses the GNU Readline library in emacs mode by default; Zsh’s line editor uses the same keys. Alt is the Meta key: if Alt does nothing on a Mac, see the terminal app section below.

KeysAction
Ctrl+A / Ctrl+EStart / end of the line
Alt+B / Alt+FBack / forward one word
Ctrl+UDelete from the cursor to the start of the line
Ctrl+KDelete from the cursor to the end of the line
Ctrl+W / Alt+DDelete the word before / after the cursor
Ctrl+Y / Alt+YPaste the last deleted text / cycle through older deletions
Ctrl+_ (or Ctrl+X Ctrl+U)Undo
Ctrl+T / Alt+TSwap two characters / two words
Alt+U / Alt+L / Alt+CUppercase / lowercase / capitalise the next word
Ctrl+LClear the screen, keep the current line
Ctrl+X Ctrl+EOpen the line in $VISUAL or $EDITOR; it runs when you save and quit
Alt+#Comment out the line and save it to history without running it
Tab, Tab TabComplete; list the possibilities
set -o vi / set -o emacsSwitch to vi or back to emacs keys. bind -p lists every binding

History search and reuse

Keys or commandAction
Ctrl+RSearch history backwards as you type; Ctrl+R again for older matches
Ctrl+SSearch forwards. Most terminals grab it for flow control, so run stty -ixon first
Ctrl+GLeave the search without running anything
Ctrl+P / Ctrl+N (or Up / Down)Previous / next command
Alt+. (or Alt+_)Insert the last argument of the previous command; repeat to go further back
Ctrl+ORun the current history line and load the next one; good for replaying a sequence
history 20Last 20 commands with numbers
HISTCONTROL=ignorebothSkip duplicates and lines starting with a space
HISTTIMEFORMAT='%F %T 'Show a date and time in history output
shopt -s histappendAppend to ~/.bash_history instead of overwriting it when several shells exit

With HISTCONTROL=ignoreboth set, a command typed with a leading space, such as mysql -p'secret', is not saved to history. It still shows in ps while it runs, so keep passwords in option files.

History expansion

SyntaxExpands to
!!The whole previous command
!$ / !^Last / first argument of the previous command
!:2, !*Second argument; all arguments
!42, !-2Command number 42; the command two back
!sshThe most recent command starting with ssh
!ssh:pPrint that command without running it (it is added to history, so !! then runs it)
^gamma^deltaRerun the previous command with the first gamma replaced by delta
!!:gs/alpha/omega/Rerun with every alpha replaced
$ cp /etc/nginx/nginx.conf /root/nginx.conf.bak
$ ls -l !$
ls -l /root/nginx.conf.bak

sudo !! repeats the whole previous line with sudo in front, but only the first command of a list gets root. On our test, ls -d /tmp && echo ok became sudo ls -d /tmp && echo ok, where echo ran as the normal user. History expansion works only in interactive shells, not in scripts.

Job control and signals

Keys or commandAction
Ctrl+CSend SIGINT: interrupt the foreground program
Ctrl+ZSend SIGTSTP: suspend it and get the prompt back
Ctrl+DEnd of input. On an empty prompt it logs you out
command &Start in the background; $! holds its PID
jobs -lBackground and stopped jobs with PIDs
fg %1 / bg %1Bring job 1 to the foreground / resume it in the background
waitWait for all background jobs to finish
disown %1Remove a job from the shell’s table so it is not sent SIGHUP when you log out
nohup long-task > task.log 2>&1 &Start a job that ignores hang-ups from the start

For server admins: to leave a long job running after you log out of SSH, press Ctrl+Z, then bg, then disown. For planned work, start it inside tmux or screen.

Redirection and pipes

SyntaxWhat it does
cmd > file / cmd >> fileWrite stdout to a file / append
cmd 2> err.logWrite stderr to a file
cmd > all.log 2>&1Both streams to one file. Order matters: 2>&1 > file sends stderr to the terminal
cmd &> all.logBash and Zsh shorthand for the line above
cmd |& lessPipe stdout and stderr (same as 2>&1 |)
set -o noclobber and >|Refuse to overwrite files with >; >| overrides it once
cmd <<< "text"Here-string: a string as stdin
cat <<EOF ... EOFHere-document; variables are expanded. Quote it (<<'EOF') to keep $ literal
diff <(sort a) <(sort b)Process substitution: command output as a file name
cmd | tee out.txtShow output and save it
a && b, a || bRun b only if a succeeds / fails
${PIPESTATUS[@]}Exit codes of every command in the last pipeline
set -o pipefailA pipeline fails if any part fails, not just the last
$ false | true; echo "status=$? pipestatus=${PIPESTATUS[*]}"
status=0 pipestatus=1 0
$ set -o pipefail; false | true; echo $?
1

Globbing, brace and parameter expansion

SyntaxResult
*.log, ?.txt, [ab].logAny string, one character, one of a set
shopt -s nullglobA pattern with no matches expands to nothing instead of itself
shopt -s globstar then **/*.logRecursive match through subdirectories
shopt -s dotglobInclude hidden files in *
shopt -s extglob then !(*.log), *.@(log|txt)Everything except .log; .log or .txt. Turn extglob on in an earlier line
{a,b,c}.confa.conf b.conf c.conf
{01..10..3}01 04 07 10 (zero-padded, step 3)
cp nginx.conf{,.bak}cp nginx.conf nginx.conf.bak
mkdir -p site/{css,js,img}Three directories in one command
${f##*/}, ${f%/*}File name and directory of a path
${f%.log}.bak, ${f/access/error}Swap a suffix; replace the first match
${VAR:-default}, ${VAR:?message}Use a default; stop with an error if unset or empty

In a script, put shopt -s extglob on its own line before any !(...) pattern. Bash parses the whole line before running it, so the same line gives a syntax error.

Zsh differences

BehaviourBashZsh
Default shell on macOSNo (old Bash 3.2 still ships)Yes, since macOS Catalina
Glob with no matchLeft as typedError no matches found; quote URLs and scp host:*.log
Recursive **/Needs shopt -s globstarOn by default
Array indexesStart at 0Start at 1
Key bindingsbind, ~/.inputrcbindkey; bindkey -e for emacs keys, bindkey -v for vi
History expansion, Ctrl+R, job controlAs aboveSame keys and syntax

tmux and screen basics

tmux and screen keep sessions running on the server after your SSH connection drops. Every key below follows the prefix: Ctrl+B in tmux, Ctrl+A in screen.

Actiontmuxscreen
New named sessiontmux new -s workscreen -S work
List sessionstmux lsscreen -ls
Reattachtmux attach -t workscreen -r work (-d -r to take it from another terminal)
Detachprefix dprefix d
New windowprefix cprefix c
Next / previous windowprefix n / prefix pprefix n / prefix p
Pick from a listprefix wprefix “
Split side by sideprefix %prefix | (then prefix Tab, prefix c for a shell)
Split top and bottomprefix “prefix S
Move between panesprefix arrow keys or prefix oprefix Tab
Zoom a paneprefix z—
Scroll back / copy modeprefix [ (q to leave)prefix [
Kill pane / windowprefix x / prefix &prefix k
tmux new -d -s upgrade 'dnf -y upgrade 2>&1 | tee /root/upgrade.log'
tmux attach -t upgrade     # watch it; prefix d to leave it running

Terminal apps: macOS, iTerm2 and Windows Terminal

ActionmacOS TerminaliTerm2Windows Terminal
New tabCmd+TCmd+TCtrl+Shift+T
Split paneCmd+DCmd+D (side by side), Cmd+Shift+D (top and bottom)Alt+Shift+Plus (right), Alt+Shift+Minus (down)
Close paneShift+Cmd+D (split)Cmd+W (Shell > Close)Ctrl+Shift+W
Clear scrollbackCmd+KCmd+K (Edit > Clear Buffer)Command palette: Clear buffer
FindCmd+FCmd+FCtrl+Shift+F
Copy / pasteCmd+C / Cmd+VCmd+C / Cmd+VCtrl+C (only with a selection) / Ctrl+V, or Ctrl+Shift+C / Ctrl+Shift+V
Command palette or quick switcher—Cmd+Shift+O (Open Quickly, finds sessions)Ctrl+Shift+P

On a Mac, Alt shortcuts such as Alt+B and Alt+. need the Option key to act as Meta. In Terminal, tick Settings > Profiles > Keyboard > Use Option as Meta key. In iTerm2, set Left Option key to Esc+ under Settings > Profiles > Keys. Option-click in macOS Terminal moves the cursor to that point on the command line.

Official documentation (checked 9 October 2026): Bash Reference Manual · GNU Readline User Interface · tmux(1) manual · GNU Screen manual · Apple: Keyboard shortcuts in Terminal on Mac · iTerm2 documentation · Windows Terminal: Panes · Windows Terminal: Actions

Terminal Cheat Sheet at a glance

Terminal Cheat Sheet – short answer
In short: Keyboard shortcuts and shell features for Bash and Zsh: line editing, history, job control, redirection, globbing, tmux and terminal apps.
Terminal Cheat Sheet – what this guide covers
Terminal Cheat Sheet: what this guide covers.

Related: Linux Commands Cheat Sheet for Server Admins · Git Cheat Sheet: Branches, Undo, Remotes and Deploys · Online Linux Terminal.

Reading a lot of our guides? Go ad-free with srvScripts Pro for $6 a month. It also pays for new guides. Cancel any time.

Share this guide

Free website test

Is your website set up right?

Check SSL, security headers, redirects, robots.txt, sitemap, llms.txt and security.txt in one test. It takes about 30 seconds.