Here is the video version, if you prefer it:
Let’s talk about history. No, not about a high school history class or about your browsing history (that could spark interesting conversations for sure). I’m talking about the
history command is used to display your command execution history. (Shotts, 2019) Example usage:
mislav@mislavovo-racunalo:~/Linux_folder$ history | grep sudo
1075 sudo apt install nodejs npm
1081 sudo npm install npm@latest -g
Here, I look for all of the
sudo prefixed commands that I have executed. It is important to note that history doesn’t go on till the beginning of your bash usage – it is limited, although you can change how much history entries you keep. Keep that in mind.
Your history is stored in a file called
.bash_history in your home directory (the first dot in the filename indicates it is a hidden file).
I didn’t use
history as much, but I was aware of its existence. I have found myself looking for the commands I ran by using the Up/Down arrows on the keyboard. history seems to be a better choice for when the command was used in the not-so-recent past.
Hope you learned something useful!
Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Page 110