Command History Searching
Using this trick you can speed up a lot your work at command line in Linux (and not only). Pressing Ctrl + R allows you to quickly find a previously used command.
How to use it?
- In command line terminal press Ctrl + R.
-
Start typing some part of command, for example `pul`:
(reverse-i-search)`pul': git pull
- If you want to find a next match, press Ctrl + R again (repeat until successful).
- If you want to edit the current match press LEFT or RIGHT and edit the command.
- If you want to exit without running any command, press Ctrl + G.
- If command you need is displayed, press ENTER to run it.
Useful shortcuts
These shortcuts are not related to the bash history tool (Ctrl+R), but may be useful if you edit a found command.- Ctrl + LEFT/RIGHT - jump over the words.
- Ctrl + A - move the cursor to the beginning of the line.
- Ctrl + E - move the cursor to the end of the line.
- Ctrl + U - remove the content from the beginning of the line to the cursor.
- Ctrl + K - remove the content from the cursor to the end of the line.
- Ctrl + W - remove word on the left.
- Ctrl + C - cancel the current command line.
Tags
To tag a command you can use a normal bash comment. Then using Ctrl + R search the command by assigned tag.
-
Tag a command:
$ somecommand #mytag
Everything after `#` in the line is ignored by bash, but remains in history.
-
Search by tag:
(reverse-i-search)`my': somecommand #mytag
Comments
Post a Comment