To rerun a command from your
history, use ! followed by its number (e.g., !123), or use !! for the very last command, !-2 for the second-to-last, or press Ctrl+r and type part of the command to search for it, then hit Enter. By History Number
- View History: Type
historyand press Enter to see a numbered list. - Re-run: Type
!then the number of the command (e.g.,!567to run command #567).
Shortcuts
!!: Runs the immediately preceding command.!-2: Runs the second-to-last command.!string: Runs the most recent command starting withstring(e.g.,!lsruns the lastlscommand).
Reverse Search (Ctrl+r)
- Press
Ctrl+rto enter interactive search mode. - Type part of the command you're looking for (e.g.,
ssh). - Press
Ctrl+ragain to cycle through older matches. - Press Enter to run the command, or Esc to exit search without running.
- If you have cycled through some older matches, now you want to cycle
through some new matches, you can add the following line to your~/.bashrcfile:
stty -ixonStarting now, you can press
Ctrl+s to cycle through new matches.
No comments:
Post a Comment