Date/Timestamp in the .bash_history

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?
4 answers Last reply
More about date timestamp bash_history
  1. 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.
  2. 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
  3. 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)
  4. 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?

Ask a new question