Is there a command like time that can display the running time details of the last or past executed commands on the shell?
Is there a command like time that can display the running time details of
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I do not know, how it is in bash, but in zsh you can define
preexecandprecmdfunctions so that they save the current time to variables$STARTTIME(preexec) and$ENDTIME(precmd) so you will be able to find the approximate running time. Or you can define anaccept-linefunction so that it will prependtimebefore each command.UPDATE:
This is the code, which will store elapsed times in the
$_elapsedarray:Then if you run
sleep 10s:No need in four variables. No problems with names or additional delays. Just note that
$_elapsedarray may grow very big, so you need to delete the first items (this is done with the following piece of code:(( $#_elapsed > 1000 )) && set -A _elapsed $_elapsed[-1000,-1]).UPDATE2:
Found the script to support zsh-style precmd and preexec in bash. Maybe you will need to remove
typeset -ig(I used just to force$_startto be integer) and replaceset -A var ...withvar=( ... )in order to get this working. And I do not know how to slice arrays and get their length in bash.Script: http://www.twistedmatrix.com/users/glyph/preexec.bash.txt (web.archive)
UPDATE3:
Found one problem: if you hit return with an empty line preexec does not run, while precmd does, so you will get meaningless values in
$_elapsedarray. In order to fix this replace theprecmdfunction with the following code: