Every shell keeps a history of commands you've typed, and you don't have to scroll through it manually to reuse one. Press the up arrow to cycle backward through recent commands, or use Ctrl+R to search your history by typing a fragment of the command you remember. Both work the moment you open a terminal or SSH in.
These shortcuts save the most time on long commands: a multi-flag rsync, a database dump with connection details, or an SSH command to a specific host. Type it once, then recall and tweak it instead of retyping from scratch.
The basics: up arrow and history
Every interactive shell (bash, zsh, the shell you get over SSH) keeps its own history file. Press the up arrow to walk backward one command at a time, and down arrow to walk forward again. Press Enter to run the command as-is, or edit it first with the left/right arrows and backspace.
To see your whole history at once, run:
history
This lists recent commands with numbers. You can rerun a specific one with ! followed by its number, for example !482. This is fragile if the numbers shift, so it's mostly useful for a quick rerun in the same session.
Reverse search with Ctrl+R
The fastest way to find a command you've run before is reverse incremental search. Press Ctrl+R, then start typing any part of the command. The shell jumps to the most recent match as you type. Press Ctrl+R again to step further back through older matches, or press Enter to run the one showing.
If the match isn't quite what you want, press the right or left arrow to drop out of search mode and land on that command line for editing, rather than running it immediately. Press Ctrl+C to cancel the search entirely and get back to an empty prompt.
This is especially useful for commands you run rarely but not never, like a mysqldump against a specific database, a tar command with the right exclude flags, or an rsync to a particular directory. Type a distinctive word from the command and Ctrl+R finds it in seconds.
Editing the recalled line
Once a command is on your prompt, whether from the up arrow or a search, you're not stuck running it verbatim. A few shortcuts make edits fast:
Ctrl+Ajumps to the start of the line,Ctrl+Ejumps to the end.Ctrl+Uclears from the cursor to the start of the line,Ctrl+Kclears from the cursor to the end.Alt+BandAlt+Fmove backward and forward one word at a time, faster than holding an arrow key.Ctrl+Wdeletes the word before the cursor.
Combine these with a recalled command: pull it up with Ctrl+R, jump to the hostname or filename with Alt+B, delete it with Ctrl+W, and type the new value.
Quick substitution shortcuts
Bash and zsh both support a shorthand for fixing a typo in the last command without retyping it:
^oldtext^newtext
Running this replaces the first occurrence of oldtext with newtext in your previous command and re-executes it. It's a one-shot fix, useful right after a command fails because of a small mistake.
!! reruns the last command outright. This is commonly paired with sudo, if you forgot to prefix a command that needed root: sudo !! reruns the previous command with sudo in front.
Where root matters: shared hosting vs VPS
On a VPS, you have root SSH access, so history and these shortcuts apply to any command on the box, including system-level ones like package installs or service restarts. On shared hosting, your SSH session runs as your own account with no root access, so history works the same way, but it's scoped to whatever commands your account can run: file operations, Git, WP-CLI if it's available, and similar user-level tools.
Either way, history is per-user and per-shell. If you SSH in as different users or switch shells, don't expect one history to show commands from the other.
A note on sensitive commands
History saves commands verbatim, including any passwords or tokens you typed directly on the command line, like a database connection string with a password in it. If you've done this, consider removing that line from your history file, and prefer prompts or config files for credentials where the tool supports it, so they never land in your shell history at all.