Bash history that stores execution time

bashcommand historytime

Is it possible to have your bash history save the total execution time of every command you run?

i.e. as if every command were prefaced with 'time' and the result was stored in the history along with the command?

clarification: I already know that you can add a timestamp of when the command was started – but I would like to know the total execution time, not just when it was started.

Best Answer

By defining HISTTIMEFORMAT in your startup scripts, you will have a timestamp added to every line of your bash history file. The value of this variable is the way (*) timestamps must be printed on the screen. Here is mine :

HISTTIMEFORMAT='%F-%T '

(*) See man 3 strftime (if you don't have it, man date should do the trick)

Related Question