Ctrl+R: the search that changes your life
Ctrl+R is bash history search. Seed a few commands, search backward, and stop rebuilding long lines from memory.
You already typed the command. Bash kept it.
People remember flags, hostnames, and paths badly. Then they retype a long command, miss one character, and waste another minute.
First, set -o history confirms the shell is recording — it’s usually already on, but worth showing. Then history -s loads three commands directly into history, standing in for the ones you’d have typed over time. history | tail -3 confirms they’re sitting there. Press Ctrl+R, type a fragment, and bash walks backward through history until it finds the last matching line — one Enter away from running.
set -o history # make sure this shell records history
history -s 'git status'; history -s 'docker ps'; history -s 'ssh root@box'
history | tail -3 # confirm the lines exist
# now press Ctrl+R, type ssh, and bash searches backward
1 git status
2 docker ps
3 ssh root@box
bash-3.2$ set -o history; history -s "git status"; history -s "docker ps"; history -s "ssh root@box"
(reverse-i-search)`ssh': ssh root@box
Ctrl+R turns history into an index. Type a fragment, get the last matching command, hit Enter, and move on.
Press Ctrl+R once before you retype anything.
#bash#terminal#productivity#linux
❯ exit 0