Sign in with
Sign up | Sign in
Your question

Date/Timestamp in the .bash_history

Last response: in Linux/Free BSD
February 23, 2007 12:42:05 PM

I have been working on a way to put a date/timestamp on the .bash_history entries. I have tried HISTTIMEFORMAT='%a %T' but that didn't work. Is there another way of doing it?

More about : date timestamp bash history

February 23, 2007 1:09:43 PM

The HISTTIMEFORMAT environment variable only will format the timestamp if used with the history command, simply setting the HISTTIMEFORMAT environment variable puts the Epoch time in the .bash_history. If you want to use the timestamp in something else, write a script that will convert it. If you need further help, come back.
February 23, 2007 1:20:27 PM

Thanks for the response. I forgot to add my bash version is 2.05b and the histtimeformat command doesn't work below 3.0. I have a cron job that appends the date and time to the history file for root every hour so I can narrow down trouble shooting. Again thanks
February 25, 2007 11:14:39 PM

I was going to add that but no need. Excellent self-made solution, you might want to make sure to append a pound sign (#) to the start of that timestamp so as to prevent the timestamp from showing up as a command (i.e. when scrolling through previous commands using the "bang" feature of shells or simple scrolling through previous commands with the up arrow)
February 26, 2007 12:42:46 AM

As bmouring said that is a fine solution :-D

On thing though, 2.05b is a bit old and probably vulnerable and your distro is probably a bit dated as well if it comes with 2.05b so you might want to consider upgrading.

What distro/version do you have?