Loading blogs…
Terminal4 min read
Keyboard shortcuts, history tricks, brace expansion, xargs and more — practical Bash and Zsh tricks that make you much faster in the terminal.
Full-stack engineer, New Delhi
Most time lost in the terminal isn't in the commands — it's in retyping, scrolling and fixing typos. These are the tricks I use every day. All of them work in Bash, and almost all in Zsh.
| Shortcut | What it does |
|---|---|
Ctrl+A / Ctrl+E | Jump to start / end of the line |
Alt+B / Alt+F | Move back / forward one word |
Ctrl+W | Delete the word before the cursor |
Ctrl+U / Ctrl+K | Delete to start / end of the line |
Ctrl+Y | Paste back what you just deleted |
Ctrl+L | Clear the screen (keeps what you typed) |
Ctrl+X Ctrl+E | Open the current command in your editor |
That last one is a lifesaver for long one-liners: edit comfortably in Vim or nano, save, and it runs.
Ctrl+R — search your history as you type. Press it again to cycle through older matches.!! — the previous command. Forgot sudo? sudo !!!$ — the last argument of the previous command: mkdir project && cd !$Alt+. — inserts the last argument, and pressing again cycles back through earlier ones^old^new — rerun the last command with a replacement: ^stagging^staginghistory | grep docker then !123 to rerun entry 123Make history bigger and shared between terminals — add to ~/.bashrc:
HISTSIZE=100000
HISTFILESIZE=200000
HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"mkdir -p app/{components,lib,styles}
cp config.yml{,.bak} # → cp config.yml config.yml.bak
touch day{01..31}.mdcd - jumps back to the previous directory.shopt -s globstar in Bash): ls **/*.test.ts$(...) drops a command's output into another: kill $(pgrep -f "node server")sort | uniq -c | sort -rn — the classic "top N":# most common status codes in an nginx log
awk '{print $9}' access.log | sort | uniq -c | sort -rn | headxargs turns lines into arguments; -P runs them in parallel:fd -e png | xargs -P 8 -I{} cwebp -q 80 {} -o {}.webptee writes to a file and still passes output on — and | sudo tee file is how you write to root-owned files.diff <(ls dir-a) <(ls dir-b)column -t turns messy whitespace output into a readable table.watch -n 2 'command' reruns anything every two seconds.Ctrl+Z pauses a running program; bg resumes it in the background, fg brings it back.command &> log.txt & runs in the background with all output in a file.nohup or disown keeps it running after you close the terminal.ss -tulpn shows what's listening on which port (the modern netstat).lsof -i :3000 — who is using port 3000?df -h — free space on every mount.tail -f file follows a growing log; less +F does too, and lets you scroll.rsync -avh --progress src/ dest/ — copying that can resume and shows progress.alias gs='git status -sb'
alias ll='ls -lah'
alias ..='cd ..'
alias please='sudo $(fc -ln -1)'mkcd function: mkcd() { mkdir -p "$1" && cd "$1"; }set -euo pipefail at the top of every Bash script, so errors stop the script instead of silently continuing.tldr command — community-written examples instead of a 40-page man page.Want to go further? Swap a few classic tools for their faster modern versions — I cover my favourites in modern CLI tools worth installing.
Linux
Use ed25519 keys, ~/.ssh/config shortcuts, jump hosts and port forwarding like a pro — then harden your server's SSH daemon.
Tools
Keep your .bashrc, .zshrc, git, Neovim and terminal configs in one git repo and symlink them anywhere with GNU Stow — set up a new Linux machine in minutes.
Tools
ripgrep, fd, bat, eza, fzf, zoxide and more — faster, friendlier replacements for grep, find, cat and ls, with install commands and config.