Comments on Adding Date And Time To Your Bash History
Adding Date And Time To Your Bash History This is a quick but handy addon (RedHat/CentOS) to enhance your bash history (bash > 3.0). It comes in handy particularly if there are multiple people maintaining a given server (so you can see when a command was performed) or even if you are the sole maintainer, but can't remember exactly when you did or changed something.
11 Comment(s)
Comments
Excellent tip, thanks!
I prefer snoopy package which writes on syslog all commands Because the .bash_history can be erased by the system
It works also in my Ubuntu box. The file to modify is $HOME/.bashrc
To make it global and permanent to all users, edit /etc/profile and append to the bottom.
HI
For me this is not working in Redhat RHEL 3 version . Though i edited the file in /etc/profile
export HISTTIMEFORMAT="%h/%d - %H:%M:%S "
Yes, I think your tip could be a great help. Thank a lot for this :)
Keep up the great work!!!!
Very nice!
Works on Ubuntu/Debian too!
Well thank you very much, just a little nifty thing I wasn't looking for but am glad to find!!!
With SuSE 11.2 you should consider modify /etc/bash.bashrc.local instead.
Nice, i was looking on how to add AM/PM to the timestamp. While searching i stumbled upon this.. "HISTTIMEFORMAT takes format string of strftime. Check out the strftime manual to choose and construct the timestamp that suit your taste." on another site. Here is a list of character's (%a, %A, %b, %B, %c, %C etc.) and what they can do to further modify your HISTTIMEFORMAT:
https://www.kernel.org/doc/man-pages/online/pages/man3/strftime.3.html
here are some more examples like the ones shown above:
export HISTTIMEFORMAT="%a %h %d - %r "
will display:
457 Sat Sep 22 - 07:37:28 PM asdsa
458 Sat Sep 22 - 07:37:29 PM history
export HISTTIMEFORMAT="%A %h %d - %r "
will display:
459 Saturday Sep 22 - 07:39:53 PM sdfsad
460 Saturday Sep 22 - 07:39:54 PM history
export HISTTIMEFORMAT="%A %B %d - %r "
will display
459 Saturday September 22 - 07:39:53 PM sdfsad
460 Saturday September 22 - 07:39:54 PM history
Why put in a timestamp that isn't sortable??? Just use "%F %T" and be done with it!