Using bash history to get a previous command, copy it and then 'run' it but with the command commented

后端 未结 10 1137
伪装坚强ぢ
伪装坚强ぢ 2021-01-29 20:34

Just a question to improve my bash skills. I always do this:

$ history | grep some_long_command

...
...
123 some_long_command1.........
124 some_l         


        
10条回答
  •  萌比男神i
    2021-01-29 21:10

    Instead of using the history command, bind history-search-backward/history-search-forward to key shortcuts which can be remembered easily (I prefer PgUp/PgDown). To do that, put this into your .inputrc file:

    "":  history-search-backward
    "":  history-search-forward
    

    To get , type Ctrl-V in the shell, and replace the starting ^[ with \e in whatever was output.

    After this is set up, you can just type some and press PgUp to get some_long_command. If you need some_long_command with_some_arg but there is a similar command some_long_command with_some_other_arg later in the history, you can cycle through until you reach it by typing some and then hitting PgUp repeatedly, or you can type some, hit PgUp, move the cursor to where the two commands start to differ, type a few characters and hit PgUp once more. This ability to quickly page through / differentiate between similar commands makes it in my opinion a much more comfortable tool than Ctrl-R.

提交回复
热议问题