How can the last command's wall time be put in the Bash prompt?

Posted by Mr Fooz on Stack Overflow See other posts from Stack Overflow or by Mr Fooz
Published on 2009-12-07T20:02:01Z Indexed on 2010/04/28 19:07 UTC
Read the original article Hit count: 229

Filed under:
|
|

Is there a way to embed the last command's elapsed wall time in a Bash prompt? I'm hoping for something that would look like this:

[last: 0s][/my/dir]$ sleep 10
[last: 10s][/my/dir]$

Background

I often run long data-crunching jobs and it's useful to know how long they've taken so I can estimate how long it will take for future jobs. For very regular tasks, I go ahead and record this information rigorously using appropriate logging techniques. For less-formal tasks, I'll just prepend the command with time.

It would be nice to automatically "time" every single interactive command and have the timing information printed in a few characters rather than 3 lines.

© Stack Overflow or respective owner

Related posts about bash

Related posts about time