History: View and recall the terminal command history
I am chronically forgetful, stratospheric, abysmal. I don't remember anything and above all I don't remember what I should at the moment I need it.
Luckily the command comes to my aid history, which isn't actually a command at all (it is not present among the executable programs), but it is more of a shortcut present within the shell itself. The output may differ depending on the terminal used. I'm using it bash and the article shows this typology.
Let's see it in action:
~$ history
And this is the answer:
1 clear
2 ls -l
3 ps ax
4 df -h
5 sudo apt upgrade
6 history
As is understandable, the history command shows the list of commands launched up to that moment. The most recent ones at the bottom, while the older ones first.
One of the interesting aspects is that you can invoke a command by typing the corresponding number. For example in this case typing !3 will be launched ps ax.
If, however, you want to launch the last command without having to type it again, you can launch it !!.
When coupled with grep it will find the commands that match the chosen regular expressions. For example:
~$ history | grep wormhole
165 wormhole send hardware_nas.html
508 wormhole skyline.JPG
509 wormhole -h
510 wormhole send skyline.JPG
513 wormhole receive
525 history | grep wormhole
Or associated with tail we can choose the number of results.
~$ history | tail -n 3
524 history | grep ps
525 history | grep wormhole
526 history | tail -n 3




0 Comments