You input command in your linux terminal which is very long and hard to remember. It is needed to input the command again to the terminal. You find it hard to search for the command that is needed. You keep pressing up arrow again and again until the required command is found. Time is wasted during this process.
In the above image you can see all the previous commands you have used along with their respective numbers. Now let's assume you have to use the command
git clone https://github.com/asimdahall/wethanks/ which is number
56. Now you can execute the command by typing
which will execute the command on number 56.
Now let'say we have to search the previous command that we have used. For that, we can combine grep with the history command. Let's take a case here. I have to search for the command
xcrun simctl shutdown all
which I have used before but I don't remember the full command and only remember
xcrun. So for searching the command, we can combine the
grep command like this:
asims-MacBook-Pro:~ asim$ history|grep xcrun
after that you will get the following output
422 xcrun simctl shutdown all 452 xcrun simctl shutdown all 454 xcrun simctl shutdown all 502 history|grep xcrun
you get all the commands where
xcrun command is used with their respective numbers. Now you can execute the command like this:
asims-MacBook-Pro:~ asim$ !422
which will then execute the needed command.
I am sorry for the bad grammar. Feedbacks and suggestions are kindly welcome. Thank you.
You can follow me on Twitter