Reputation: 186
Every once in a while I export my bash history to an external file. On occasion I would like to add export HISTTIMEFORMAT='%F %T '
so the time/date shows in the output, although it never appears in the file after I envoke the command. I know that you can permanently add the environment variables to your .bash_profile, but I just want to use it temporarily for when I use the command below. I've tried it like this:
# export HISTTIMEFORMAT='%F %T ' | grep -v "^#" $HISTFILE > ~/path/to/output
with no luck showing the time/date stamp.
Upvotes: 1
Views: 996
Reputation: 758
Use:
HISTTIMEFORMAT='%F %T ' history | grep -v "^#" > ~/path/to/output
Note: commands that were in your history from past shells will not contain proper times unless HISTTIMEFORMAT
was set to some value during these shells.
Upvotes: 1
Reputation: 1700
it is bash that needs the environment variable:
env HISTTIMEFORMAT='%F %T ' bash -c 'command args'
Upvotes: 1