Search through your command line history

set -o vi
Once issuing the command, hit "esc" and then "k" (not together) to enter the search mode at the shell prompt (each time), and invoke the search with "/" as if you would in vi. Type a command and see the most recently used instance of that command. Use "n" and "N" to go forward and backwards through other instances of that command.

2009-12-22 20:40:10

What Others Think

You don't need the vi option set in bash to enable searching your history. By default, bash (via libreadline) has backward history search via ^R (ctrl+r).
bwoodacre · 646 weeks and 5 days ago
(ctrl+r) is close, but it doesn't allow forward and backward searching with (n) and (N).
andykazmaier · 646 weeks and 5 days ago
It allows forward and backward searching with ^R and ^S. Repeat for next/previous instance.
cfajohnson · 645 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: