Ever found yourself needing to search through your command history? Here are some quick tricks to make your terminal life easier:
๐ Search History
You can instantly rerun your last command by typing !!. Want to search for a specific command you ran? Pair history with grep:
$ history | grep conda
3 conda activate dnakey
5 history | grep conda
Need only your last few commands? Try using tail:
$ history | tail -n 3
4 history
5 history | grep conda
6 history | tail -n 3
๐ก Quick Command Fix
Made a typo in your last command? Use ^oldtext^newtext^ to replace part of it without retyping everything. For example:
$ ^conda^pip^
This reruns the previous command, but with conda replaced by pip.
๐งน Cleaning Up History
Need to delete a specific command from your history? Just specify the line number:
$ history -d <line number>
Or clear your entire history file with history -c
.
These shortcuts make navigating your command history faster and more efficient.
Top comments (0)