Pages

RHEL/CentOS: timestamps in history

Ever have someone ask you "When did you make that change"?  You login to a system, type 'history' only to realize you have a long list of commands, but no context about when you entered them.  You can easily embed date/time in your .history file.

Create a file called: /etc/profile.d/history.sh

# history settings
HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S"
HISTFILESIZE=4000
HISTSIZE=4000
readonly HISTTIMEFORMAT HISTFILESIZE HISTSIZE
export HISTTIMEFORMAT HISTFILESIZE HISTSIZE


I like to set the size to a large value, like 4000 so I can see what has happened many months back.  Now your history has a nice format with timestamps:
[aalinux]$ history
...
  663  2011-09-28 09:58:05 ls
  664  2011-09-28 09:58:08 cd /etc
  665  2011-09-28 09:58:09 ls
  666  2011-09-28 10:28:27 cat history.sh
  667  2011-09-28 10:33:16 history