Cygwin shortcut for command history

2019-04-06 14:36发布

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.

6条回答
干净又极端
2楼-- · 2019-04-06 14:44

I use the history command in combination with grep, e.g. history | grep vi shows all commands where vi was used.

查看更多
狗以群分
3楼-- · 2019-04-06 14:44

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.

history | less

and then

/text to find

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.

查看更多
Lonely孤独者°
4楼-- · 2019-04-06 14:49

The history command is the way to go. I use

h ()
{
    history | cut -f 2- | sort -u | grep -P --color=auto -e "$*"
}

so 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:

# Ctrl+Up/Down for searching command history
"\e[1;5A": history-search-backward
"\e[1;5B": history-search-forward

With these in place, you can type a partial command prefix (such as gi or sql) then use Ctrl+Up to scroll back through the list of just your command history entries that match that prefix (such as git clone https://code.google.com/p/double-conversion/ and sqlite3 .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.

查看更多
5楼-- · 2019-04-06 14:58

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-/

查看更多
够拽才男人
6楼-- · 2019-04-06 14:59

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...

查看更多
地球回转人心会变
7楼-- · 2019-04-06 15:07

Do

vi ~/.inputrc

Add

For arrow up/down bindings:

"\e[A": history-search-backward
"\e[B": history-search-forward

Or for page up/down bindings:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

Close and open cygwin.

Voila.

查看更多
登录 后发表回答