shell history search trick

Created: Nov 09, 2022Published: Nov 09, 2022Last modified: Apr 05, 2023
No tags
Word count: 150Backlinks: 1

A command line trick that I love is including a comment on the end to make searching for the command easier.

For example:

echo "crazy command i forget the name of" # my fancy search keyword

The comment is now searchable along with the command itself.

If you're not familiar, history search is typically bound to Ctrl-r, and

typically supported in a fuzzy way by tools like fzf. (Please use fzf! It's a

game changer!)

A real use-case: fixing the linux clock

I can never remember how to fix my linux clock, which slowly drifts.

> There are plenty of other ways to solve this (like encoding this fix as part of your computer's boot, or running it on a cron job). Shrug.

The command is here:

sudo ntpd -qg && sudo hwclock --systohc

But, rather than remember this arbitrary jumble of letters, you can:

sudo ntpd -qg && sudo hwclock --systohc # fix linux clock

And now I search for it via Ctrl-r and typing fix, and bada-bam, it's the first one. Thanks, past-me + fzf!


Backlinks