Administration tools

How to enable timestamp in Linux History command

The Bash history feature is an invaluable tool which allows users to recall commands previously entered into their shell with relative ease. This makes it easy to enter repeated commands and keep track of what was done on a system. By default, however, a user is unable to see whenthese commands were actually entered. When auditing a system, it can sometimes be useful to see this type of information, for example when trying to determine how and when a file may have gone missing on the file system. Since Bash version 3, however, you are able to enable time-stamping of entries for review later.
Applicable versions of Bash provide the environment variable HISTTIMEFORMAT which you can set for this purpose. Although it is empty by default, you can simple assign a time format string to enable time-stamping.

Enable timestamp in bash history

To enable time stamp on your bash history type following command on your terminal:

$ export HISTTIMEFORMAT="%F %T "

Now execute

$ history

It will print the command line history with corresponding timestamp when the command was executed.

$ # history
    1  2015-12-12 15:14:15 nmtui
    2  2015-12-12 15:14:15 ping 8.8.8.8
    3  2015-12-12 15:32:24 export HISTTIMEFORMAT="%F %T "
    4  2015-12-12 15:32:26 history

That is it!

Related Articles

One Comment

  1. Add it to your .bashrc file so it’s always there (if you like it, that is).

    export HISTTIMEFORMAT=”%F %T “

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top button