In Bash or Zsh, we can in general use the up arrow to get back the command line some 20 or 25 lines ago, edit the command, press Enter and execute it.
However, pressing the up arrow key 20 or 25 times can be tedious, and we need to look closely when we get that exact line, which can be tiring on the eyes.
One quicker way is this:
- Use
h
orhistory
to look at the list of past commands. When needed, usehistory -300
to look at 300 lines of history - Use
!127
to execute the command line 127 as shown above "as is" with no editing, but to edit it, then: - Use
!127:p
to just print that command line without executing it, and put it into history - Then, use the up arrow once and you can get that command, and edit it as you wish (using left, right arrow, CTRL-A to go to the beginning, or CTRL-R to search backward, etc, depending on your settings)
Top comments (0)