DEV Community

Mohamed Ashiq Sultan
Mohamed Ashiq Sultan

Posted on

To those who use arrow keys to find old commands.

TL;DR

  • history
  • history | grep command-name
  • Press ctrl + r -> type the command.

I hope everyone is aware that hitting the arrow keys helps us navigate to recently executed commands but what if you forgot a command you used months before and want to use it now or view all the commands you used relating to git or docker. We will see three commands I often use to achieve this.

history

Using this will list all the commands you have executed.
Alt Text

Execute a command from History

To execute any one of the commands from the list type
! <history-number>
Alt Text

history | grep

This is just the previous one but we are using the grep to filter the list.
Example, if you want to see only the commands related to docker, you would type
history | grep docker
Alt Text

ctrl + r ->

Press ctrl + r and start typing the command you knew you have executed months before. The terminal will autocomplete the command.
Example if you haven't used ssh for sometime and feel lazy about looking the history, you could press ctrl + R and type ssh The terminal will autocomplete with your recent ssh command.
Example
I have used ctrl + r then typed heroku. The terminal autocompleted with my most recent heroku command
Alt Text

Top comments (1)

Collapse
 
thefluxapex profile image
Ian Pride • Edited

The evolution of reverse lookup is FZF (works with regex and more):
FZF - Command Line Fuzzy Finder
ScreenShot