In case you are wondering how to review your latest commands entered in your favorite Unix shell, below you have more than one option to achieve this goal.
The first and most known way is using the history command:
By typing history in your Linux shell will show on your screen the latest commands you entered with the user you are currently logged in.
It is important to mention that the Unix/Linux way of storing your history is pretty simple: basically the OS just stores your commands in a text file. That file can differ from one distro to another, but you can view the exact location of that file by typing echo $HISTFILE. You can see a sample below:
Knowing the file (location) the ways you can manipulate the output are multiple. For example:
cat $HISTFILE | more #(you can use less too)
View the history in a text editor:
View only specific columns:
history | cut -d' ' -f 4-
View only the last 20 lines:
history | tail -n 20
Or view the:
- last 5 “yum-install” commands from your history file:
history | grep "yum-install" | tail -n 5
- First 5 commands that contain “yum”
history | grep yum | head