2

Setting HISTTIMEFORMAT in bash to get timestamps in the history report just isn't working:

> fgrep HISTTIMEFORMAT ~/.bashrc
export HISTTIMEFORMAT='%m-%d-%y %T '
> bash
> history | tail -20
181  git status
182  man git-push
183  history | tail 
184  help history
185  export HISTTIMEFORMAT="%d.%m.%y %T "
186  history | tail 
187  export HISTTIMEFORMAT="%m-%d-%y %T"
188  history | tail 
189  HISTTIMEFORMAT="%m-%d-%y %T"
190  history | tail 
191  echo $HISTTIMEFORMAT
192  man 3 strftime
193  set | fgrep HIST
194  HISTTIMEFORMAT='%m-%d-%y %T '
195  history | tail 
196  export HISTTIMEFORMAT='%m-%d-%y %T '
197  history | tail 
198  bash
199  export HISTTIMEFORMAT
200  history |tail -2
> set | fgrep HIST
HISTCONTROL=ignoredups
HISTFILE=/home/eewanco/.bash_history
HISTFILESIZE=200
HISTSIZE=200
HISTTIMEFORMAT='%m-%d-%y %T '
> set | fgrep BASH 
BASH=/bin/bash
BASHOPTS=cmdhist:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="1" [2]="2" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.1.2(1)-release'

I vaguely recall having similar trouble and successfully getting this to work at a previous company with a special trick but I can't remember what it was. The history file is logging timestamps correctly, in fact I was able to get the information I wanted with a date -d @ command, but I want this solved for future usage. I've seen logs of people doing precisely what I did and it works for them. It works fine on my Samsung tablet.

  • surely you don't have history aliased to something else, like fc -l? what does alias history say? – mosvy Apr 15 at 17:18
  • 1
    or better, type history? – mosvy Apr 15 at 17:28
  • Yep, that was it. Thank you. Gotta love IT for mucking with things behind the scenes. Even if I knew it was aliased, though, it's not obvious based on the help for fc that fc -l omits the timestamps. Is there a particular advantage to fc -l -$HISTSIZE over the default history command? What might possess IT to substitute the former for the latter? – eewanco Apr 16 at 12:08
  • fc is more portable -- if you share you home dir between multiple systems via nfs, it may be nice to have some stock aliases that work everywhere (I eg. have alias %=fg -- but I made it conditional on the shell used, unlike your IT department ;-)). – mosvy Apr 16 at 12:24
2

As @mosvy suggested, my IT department had history aliased to fc -l -$HISTSIZE, which doesn't show timestamps. Running \history shows me the timestamps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.