Skip to content
Related Articles

Related Articles

HISTTIMEFORMAT variable in Linux with Example

View Discussion
Improve Article
Save Article
  • Last Updated : 24 Dec, 2020
View Discussion
Improve Article
Save Article

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:

$ history

The output of the command can be seen in the image below:

history command in linux

The above command does not display the time when the command was executed and hence we use HISTTIMEFORMAT variable.



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

Histcontrol in linux

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!