Shell · Bash · Unix · Sysadmin

Shell Tricks That Actually Make Life Easier

We learn ls, cd, and grep — and then stop. The shell authors solved most of our frustrations back in 1989. Here's what they built. Split into universal POSIX tricks and Bash/Zsh extras.

Jump to
Ctrl+WDelete word before cursor

Instantly wipes the last word. Beats holding Backspace when you mistype a long path segment.

/var/log/nginx/ → Ctrl+W → /var/log/
Ctrl+UCtrl+KCtrl+YCut & Yank (paste back)

Ctrl+U cuts from cursor to line start. Ctrl+K cuts to end. Ctrl+Y yanks it back. Perfect for stashing a long command while you run a quick check.

rsync -avz /src user@host:/dest # Ctrl+U to cut ls /dest # quick check # Ctrl+Y to paste the rsync back
Ctrl+ACtrl+EJump to start / end of line

Skip the Home/End keys — these are right on the home row and much faster.

Alt+BAlt+FMove word by word

Jump backward/forward one whole word at a time instead of one character.

sudo systemctl restart nginx # ^ Alt+B moves cursor here each press
Mac users: enable "Use Option as Meta key" in your terminal settings.
Ctrl+LClear screen without losing your command

Unlike typing clear, this works mid-command. Wipes the clutter, keeps your cursor and current input intact.

resetFix garbled terminal output

Accidentally cat-ed a binary? Your terminal is showing ancient runes. Type reset blind and hit Enter — it heals itself.

cat /usr/bin/ls # oops — garbled output everywhere reset # type this even if invisible, then Enter
Ctrl+CCtrl+DEmergency exits

Ctrl+C cancels the current command. Ctrl+D sends EOF — closes input streams, or logs you out if the prompt is empty (be careful).

set -eset -uset -o pipefailSafe script header

set -e exits on error. set -u errors on unset variables — prevents disasters like rm -rf /usr/${TYPO}/*. pipefail catches failures inside pipes.

#!/bin/bash set -euo pipefail # put this at the top of every script
Learn the edge cases of set -e before relying on it inside conditionals and loops.

Ctrl+RReverse history search

Press, then type any keyword from a past command. Finds it instantly. Press again to cycle further back through matches.

Ctrl+R → type "rsync" → finds last rsync command you ran # press Ctrl+R again to go further back
!!Repeat last command

The classic "I forgot sudo" fix. Expands to your entire previous command.

systemctl restart nginx # Permission denied sudo !! # runs: sudo systemctl restart nginx
Alt+.!$Insert last argument from history

Alt+. inserts it live at cursor (you can edit before running). Press repeatedly to cycle back through history. !$ expands blindly at Enter.

vim /etc/nginx/nginx.conf # press Alt+. on next command → inserts: /etc/nginx/nginx.conf cat Alt+. → cat /etc/nginx/nginx.conf
Ctrl+X Ctrl+EEdit command in $EDITOR

One-liner grown into a four-pipe monster? Open it in Vim/Nano, edit comfortably, save and exit — shell runs it immediately.

fcFix last command in editor (portable)

Opens previous command in $EDITOR for clean edits. Works across most shells — more portable than Ctrl+X Ctrl+E.

fc # opens last command in vim to fix and re-run
{ }Brace expansion — backup, rename, bulk create

The shell expands brace expressions before running the command. Makes backups, renames, and bulk directory creation one-liners.

cp nginx.conf{,.bak} # → cp nginx.conf nginx.conf.bak mv report.{txt,md} # → mv report.txt report.md mkdir -p project/{src,tests,docs} # three dirs at once
<(command)Process substitution

Treats command output as a file. Eliminates temp files for operations like diff.

diff <(sort file1.txt) <(sort file2.txt) # no temp files, no cleanup needed
**Recursive glob (globstar)

Enable with shopt -s globstar in Bash (on by default in Zsh). Matches files in all subdirectories — often replaces a find command.

shopt -s globstar ls **/*.js # all .js files recursively grep -l "TODO" **/*.py # all Python files with TODO
Ctrl+Z → bg → disownDetach a running process from your SSH session

Forgot to use tmux before starting a long job? Suspend it, background it, then disown it. The process survives even if your SSH connection drops.

Ctrl+Z # suspends the running process bg # resumes it in background, frees your prompt disown # detaches from shell — safe to close terminal now
|& tee file.logCapture both stdout and stderr to a file

Regular | misses stderr. |& captures both. tee lets you watch live output while saving it simultaneously.

./deploy.sh |& tee deploy.log # watch in terminal AND save to file at the same time
↑ Back to top