How can I search the command history in cygwin?
I don't want to keep pressing the arrow keys to execute a command from console command history.
How can I search the command history in cygwin?
I don't want to keep pressing the arrow keys to execute a command from console command history.
I use the
history
command in combination withgrep
, e.g.history | grep vi
shows all commands wherevi
was used.I think one of the easiest way is to pipeline it with less and press search character ("/") and then type the command you wanna find.
and then
to find the desired command
Another way
is to append the stdout form history command to a file:
history > /cygdrive/path/file.txt
and then search in the document.
The
history
command is the way to go. I useso that I can type something like
h git.*MyProgram
,h ^tar -c
,h svn:ignore
, etc to pull up a sorted list of past commands matching a regex.You might also want to add the following lines to ~/.inputrc:
With these in place, you can type a partial command prefix (such as
gi
orsql
) then use Ctrl+Up to scroll back through the list of just your command history entries that match that prefix (such asgit clone https://code.google.com/p/double-conversion/
andsqlite3 .svn/wc.db .tables
). This can be a lot faster than searching and then cutting and pasting if you want to edit or re-execute a command that was fairly recent.If you are using the default editing mode, do ctrl+R to search back through your history.
If you have done set -o vi to use vi editing mode, then it is esc-/
Checkout the "Gnu Bash Manual" (
man bash
) for the command "fc". E.g.fc -l -80
would list the last 80 commands, while other options let you search with RegEx...Do
Add
For arrow up/down bindings:
Or for page up/down bindings:
Close and open
cygwin
.Voila.