Skip to content

~/avetyan.com/cheatsheets

Cheat sheets

Shell shortcuts cheat sheet

Move faster in Bash: readline keys, history search and expansion, brace expansion, globbing and the small tricks that save typing.

2 min read


Moving

KeysAction

Editing

KeysAction

Control

KeysAction
KeysAction

History expansion

SyntaxExpands to

Brace expansion

bash
cp nginx.conf{,.bak}                    # cp nginx.conf nginx.conf.bak
mv report.{txt,md}
mkdir -p project/{src,tests,docs}
echo web{1..5}.example.com
touch log-{01..12}.txt                  # zero-padded
echo {a..e}

Globbing

PatternMatches
bash
shopt -s globstar nullglob
ls **/*.yaml

Directories

bash
cd -                                    # back to the previous directory
pushd /etc/nginx; popd                  # a directory stack
cd ~alice                               # someone's home

History settings

~/.bashrc
HISTSIZE=100000
HISTFILESIZE=200000
HISTCONTROL=ignoreboth:erasedups        # skip duplicates and lines starting with a space
HISTTIMEFORMAT='%F %T '
shopt -s histappend                     # don't overwrite history from other terminals

Start a command with a space to keep it, and any secret in it, out of history.

Keep in mind

  • These are readline defaults (Emacs mode). set -o vi switches to vi keys.
  • In many terminals Alt needs to be set to send Meta. If Alt-. doesn’t work, Esc then . does the same.

Comments

Sign in with Google, GitHub or Facebook to comment.

Loading comments…