Skip to main content
3 of 5
added 8 characters in body
lcd047
  • 7.4k
  • 1
  • 24
  • 33

Write bash_history to a file with a timestamp

I need help with the script below. The requirement is to capture command line history in a file with specific date and time of commands, when they were executed.

The below script captures history with date and time but it also assigns the current date and time for older commands. Also I want to extend the script to take incremental backup of the history output file.

#!/bin/bash
. ~/.bash_profile
HISTFILE=~/.bash_history
set -o history
history >/home/user/hist_`date "+%d%b%y%T"`
SunLynx
  • 101
  • 2
  • 10