Digital Ocean is the platform that I use to host most of my projects, including this blog, and I can sincerely recommend it to my readers, using this link will not generate an extra cost on you, it helps me to keep the blog costs low and you will also get $200 USD in credit to materialize your ideas.
How to find a previously executed command in GNU Linux?
Sometimes we execute commands that solve a specific task on our system. We may have done a file lookup using regular expressions or perhaps we accessed a server via ssh and no longer remember the IP address. Re-creating the regular expression from scratch can be very time consuming and perhaps finding the IP again can also be more time consuming than if we could simply retrieve the command. We can find a previously executed command in GNU/Linux in a simple way, here is how.
One way to do this would be to perform a search for the part of the command that we remember in the command history. This can be done as follows:
history | grep "comando que buscamos"
The history command will show the list of commands used, the pipe character “|” will redirect the result to the grep command, which will search for the string you specify.
Command CTRL + R
There is an even simpler way to perform this search. This method is a keystroke combination that, despite its simplicity and ease of use, is not very popular, even among regular users of GNU/Linux environments.
First we will open a terminal, then we will press CTRL + R, this will modify the cursor as follows:
(reverse-i-search)`': history
As we press the keys, the commands that match that search will appear. If the command we are looking for is in the ~.history file, it will be displayed instantly.