brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Ctrl-o reruns a sequence of bash commands from your history

Bash
~/tips/tip-bash-ctrl-o-operate-and-get-next

Ctrl-o # runs make, then shows the next history line

Replay a few commands in a row from history, one keypress each.

Say you ran make, ./test.sh and rsync an hour ago and want the same three again. Pressing Up, finding each one, pressing Enter and starting the search over is tedious. Ctrl-o keeps your place.

Go back to the first command of the sequence, with Up or a Ctrl-r search, and press Ctrl-o instead of Enter:

Ctrl-r make    # find the old 'make' line
Ctrl-o         # runs make, then shows the next history line
Ctrl-o         # runs ./test.sh, then shows rsync
Enter          # runs rsync

Bash runs the line and then puts the command that came after it in your history on the prompt. Each Ctrl-o runs one and loads the next, so you can walk through a whole series and check every line before you press.

I like it for edit, build and test loops, where the same three or four commands come back again and again.

It follows history order, not your search, so it only helps when the commands ran right after each other the first time. Commands you ran in another terminal in between can sit in that sequence too, depending on how your history is shared. It is a bash Readline command; zsh has its own widget for the same idea.

Further reading: Bash manual: Commands For Manipulating The History

More Bash tips echo {01..10} cmd > file 2>&1 export HISTIGNORE='ls*:pwd:cd*' #rsync -av --delete /srv/media/ /mnt/backup/media/ APP_HOST=example.com All Bash tips (52) All topics

Link