Display Date And Time for History Commands

This post will guide you how to set date and time for each commands in bash shell history. How do I display date and time in history command in Linux. How to display commands history based on time and date in Linux.

Display Date And Time for History Commands


The history command will display all command you executed in bash shell, and it will do not display date and time for each command in bash history by default. So if you want to set the date and time for each command in history, you need to change another variable of history called HISTTIMEFORMAT.

Type the following command to set date and time stamps in bash history:

# HISTTIMEFORMAT="%d/%m/%y %T "

Where,

  • %d is Day format
  • %m is month format
  • %y is year format
  • %T is time format

Outputs:

root@ubuntu-dev:~# HISTTIMEFORMAT="%d/%m/%y %T "

root@ubuntu-dev:~# echo $HISTTIMEFORMAT
%d/%m/%y %T

root@ubuntu-dev:~# history
1 16/09/18 17:41:22 history
2 16/09/18 17:43:02 help history
3 16/09/18 17:46:38 vim .bash_history
4 16/09/18 17:46:54 history
5 16/09/18 19:33:27 echo $HISTSIZE
6 16/09/18 19:55:06 echo $HISTTIMEFORMAT
7 16/09/18 19:56:05 HISTTIMEFORMAT="%d/%m/%y %T "
8 16/09/18 19:56:07 echo $HISTTIMEFORMAT
9 16/09/18 19:56:11 ls
10 16/09/18 19:56:13 history

 

 

You might also like:

Sidebar



back to top