The bash shell in Linux allows us to access the command history i.e, the list of previously executed commands in sequence using the history command. The history command is used to keep track of all commands that were executed. It is very important during troubleshooting or for auditing. History command without setting the HISTTIMEFORMAT displays only command# and command but it does not display the time when the command was executed. So, to display the time stamp information associated with each history entry the HISTTIMEFORMAT has to be set.
By default, the display of the history command is only the serial number and the command. The Syntax for the history command:
The output of the command can be seen in the image below:
The above command does not display the time when the command was executed and hence we use HISTTIMEFORMAT variable.
HISTTIMEFORMAT='%d/%m/%y %T' or, HISTTIMEFORMAT="%F %T "
After using any of the above commands both date and time will be displayed along with the commands.
1 2020-12-14 14:09:17 whoami 2 2020-12-14 14:09:17 pwd 3 2020-12-14 14:09:17 echo "abc" 4 2020-12-14 14:09:17 pwd 5 2020-12-14 14:09:17 whoami 6 2020-12-14 14:09:17 clear 7 2020-12-14 14:09:17 man bash 8 2020-12-14 14:09:17 history