Retyping the same long command, or slowly arrow-keying back through history to fix a typo, is the single most common way people make the terminal feel slower than it has to be.
3 min read
Every command you run is saved to a history file (~/.bash_history or
~/.zsh_history, depending on your shell). You've probably already used the
up arrow to step backward through it — but a few underused shortcuts make
that history far more useful than scrolling one line at a time.
# Reverse search: type Ctrl+R, then start typing part of a past command
(reverse-i-search)`git com': git commit -m "fix login bug"
# Press Ctrl+R again to cycle to older matches, Enter to run it
# Re-run the last command
$ !!
$ sudo !! # a very common pattern: forgot `sudo`, re-run the last
# command with it prepended
# Re-run the last command that started with a given word
$ !ping # re-runs the most recent command starting with "ping"
# Reuse the last argument of the previous command
$ mkdir new-project
$ cd !$ # !$ expands to "new-project" — cd into what you just madeCtrl+R alone is worth more than the rest combined — searching history by
content, rather than counting how many presses of the up arrow a command is
away, turns "I know I ran something like this yesterday" into a two-second
lookup instead of a re-typed command.
Pressing Tab completes a partially-typed file name, directory, or (for many
tools) command flags — and pressing it twice when the first press doesn't
finish anything lists every possible match. Typing cd Doc<Tab> completing
to cd Documents/ isn't just fewer keystrokes; it also avoids the actual
class of bug where a manually-typed filename has a typo the shell would
otherwise silently fail on with "No such file or directory."
An alias is a shortcut name for a longer command, defined in your shell's config file (covered in the environment variables and shell configuration lesson):
# in ~/.bashrc or ~/.zshrc
alias gs="git status"
alias ll="ls -la"
alias ..="cd .."Once defined and reloaded (source ~/.bashrc), typing gs runs git status
exactly as if you'd typed it out. Aliases are especially worth creating for
any command you find yourself typing identically, several times a day.
None of these shortcuts change what's possible in the shell — everything here is also achievable by typing the full command out every time. What they change is friction: a terminal that requires re-typing or slowly scrolling for anything not run in the last few commands feels slow enough that people avoid it in favor of a GUI, even when the command line would genuinely be faster. Fixing that friction is most of what separates someone comfortable in a terminal from someone who dreads opening one.
Check your understanding
A quick comprehension check — not tracked, not graded, just for you.
1. What does pressing Ctrl+R do in the shell?
2. What does `sudo !!` do?
3. What's the main benefit of defining a shell alias like `alias gs="git status"`?
Linux & the Command Line