mobile logo

bash_history date

posted on July 11, 2010 / IN Linux / Quick Tip / 0 Comments

Bash_history date

Ever try to determine what caused the latest outage by trying to determined when a command was last executed?

Look in your .bash_history (if you are running a bash shell), and you will see your recently executed commands. However, it is generally impossible to tell when the command was executed.

Part of our job includes figuring out how a problem occurred, and then implementing solutions to prevent this problem from happening again. By using HISTTIMEFORMAT with bash, we can enable timestamps in the history command, allowing for much better auditing and correlation of problems.

Below is example output of the history command without HISTTIMEFORMAT:

$ history | tail -3
994 ping
995 ls -lart
996 grep POST access_log

To enable timestamps globally (for all users) in your history output you need the following settings:

  • On Ubuntu systems edit /etc/bash.bashrc
  • On Red Hat /CentOS systems edit /etc/bashrc and add the following:

  • export HISTTIMEFORMAT='%F %T '

    Below is example output of the history command with HISTTIMEFORMAT:

    $ history | tail -3
    1004 2010-07-11 13:29:29 ping
    1005 2010-07-11 13:29:34 ls -lart
    1006 2010-07-11 13:29:38 grep POST access_log

    Using bash_history with HISTTIMEFORMAT enabled makes our job easier, and will help you when trying to debug issues in the future.

    Stop worrying about your server issues

    Click here for additional detail or request a proposal so you can start focusing on growing your business, rather than supporting your servers.

    By admin

    No Comments

    Please use the form to leave a comment

    Leave a comment.