Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 758965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:32:29+00:00 2026-05-14T15:32:29+00:00

Is there a command like time that can display the running time details of

  • 0

Is there a command like time that can display the running time details of the last or past executed commands on the shell?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:32:30+00:00Added an answer on May 14, 2026 at 3:32 pm

    I do not know, how it is in bash, but in zsh you can define preexec and precmd functions 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 an accept-line function so that it will prepend time before each command.

    UPDATE:
    This is the code, which will store elapsed times in the $_elapsed array:

    preexec () {
       (( $#_elapsed > 1000 )) && set -A _elapsed $_elapsed[-1000,-1]
       typeset -ig _start=SECONDS
    }
    precmd() { set -A _elapsed $_elapsed $(( SECONDS-_start )) }
    

    Then if you run sleep 10s:

    % set -A _elapsed # Clear the times
    % sleep 10s
    % sleep 2s ; echo $_elapsed[-1]
    10
    % echo $_elapsed
    0 10 0
    

    No need in four variables. No problems with names or additional delays. Just note that $_elapsed array 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 $_start to be integer) and replace set -A var ... with var=( ... ) 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 $_elapsed array. In order to fix this replace the precmd function with the following code:

    precmd () {
       (( _start >= 0 )) && set -A _elapsed $_elapsed $(( SECONDS-_start ))
       _start=-1 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any command in Visual basic that can execute a function every time
I know there is a command that updates the changes like c:\svn up <working
Is there a POSIX function that works like the which command? That is, I
Is there any analogue for unix command substitution shell expansion? Like > cmd1 `cmd2
I have a Shell command that I'd like to run in the background and
I know there exists a command like jQuery.noConflict. But for this it first registers
I am wondering whether there is a vi like editor under windows command line?
Is there any command in gdb by which one can apply breakpoint at the
Is there a .NET library that I can use to sync a folder to
Is their any cases in C++ Like these case WM_COMMAND: switch(LOWORD(wParam)) That happen when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.