β„‚π• π•Ÿπ•₯π•šπ•Ÿπ•¦π•¦π•ž

Bash Tips

Last update: 2026-11-09

Tags: bash cheatsheet code

A cheat sheet for working faster at the command line, with macOS extras.

1. Editing the command line

Shortcut What it does
Ctrl+A Jump to the start of the line
Ctrl+E Jump to the end of the line
Ctrl+W Delete the previous word
Ctrl+U Delete from the cursor to the start of the line
Ctrl+K Delete from the cursor to the end of the line
Ctrl+Y Paste back whatever you just deleted with Ctrl+U, Ctrl+K, or Ctrl+W
Alt+B / Alt+F Move back or forward one word (needs Option as Meta; see setup notes)
Ctrl+X, Ctrl+E Open the current command in $EDITOR; handy for long commands
Ctrl+L Clear the screen (keeps your current line)

2. History

Shortcut What it does
Ctrl+R Search your command history
Alt+. Reuse the last argument of the previous command
!! Repeat the last command
sudo !! Rerun the last command as root
!$ Last argument of the previous command (same idea as Alt+.)
!abc Rerun the most recent command that started with β€œabc”
^old^new Rerun the previous command, replacing the first β€œold” with β€œnew”
history \| grep word Find an old command by keyword
Command What it does
cd - Jump back to the previous directory
cd Go to your home directory
pushd dir / popd Keep a stack of directories and hop back to them
Tab Tab Show all possible completions

4. Jobs and processes

Shortcut What it does
Ctrl+C Stop the running command
Ctrl+Z Suspend the running command
bg Resume a suspended job in the background
fg Bring a job back to the foreground
jobs List background and suspended jobs
Ctrl+D End input, or exit the shell (on an empty line)

5. Expansion and chaining

Example What it does
cp file.txt{,.bak} Brace expansion: copies to file.txt.bak
mkdir -p project/{src,docs,tests} Create several folders at once
cmd1 && cmd2 Run cmd2 only if cmd1 succeeds
cmd1 \|\| cmd2 Run cmd2 only if cmd1 fails
$(command) Use a command’s output inside another command
type name Show whether something is an alias, function, or program, and where it lives

6. macOS extras

Command What it does
open . Open the current folder in Finder
open -a CotEditor file.txt Open a file in a specific app
pbcopy / pbpaste Pipe to or from the clipboard, e.g.Β cat file.txt \| pbcopy
brew list See what Homebrew has installed
python3 -m http.server Serve the current folder at localhost:8000

7. Setup notes and caveats