Get program execution time in the shell

0 votes
I want to execute something in a Linux shell under a few different conditions and be able to output the execution time of each execution.

I know I could write a Perl or python script that would do this, but is there a way I can do it in the shell?
Apr 14, 2022 in Linux Administration by Soham
• 9,710 points
558 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Use the built-in time keyword:

$ help time

The time: time [-p] PIPELINE executes PIPELINE and prints a summary of the real-time, user CPU time and system CPU time spent executing PIPELINE when it terminates. The return status is the return status of PIPELINE.  The `-p' option prints the timing summary in a slightly different format. This uses the value of the TIMEFORMAT variable as the output format.

Example:

$ time sleep 2

real    0m2.009s

user    0m0.000s

sys     0m0.004s

answered Apr 20, 2022 by Rahul
• 9,680 points

edited 5 days ago

Related Questions In Linux Administration

0 votes
1 answer

Input file name in the mapper in a Hadoop program

Try this inside your mapper : FileSplit fileSplit ...READ MORE

answered Jul 23, 2019 in Linux Administration by Shubham
• 13,490 points
3,447 views
0 votes
1 answer

How to change the current time in Linux system?

Hi@akhtar, You can use timedatectl command in your ...READ MORE

answered Sep 25, 2020 in Linux Administration by MD
• 95,460 points
749 views
0 votes
1 answer

Dynamic real-time view of the running system in Linux.

Hi@akhtar, The top command is used to show the ...READ MORE

answered Oct 12, 2020 in Linux Administration by MD
• 95,460 points
2,322 views
0 votes
1 answer

How to measure the time required to run a program?

Hi@akhtar, You can use the time command in ...READ MORE

answered Oct 12, 2020 in Linux Administration by MD
• 95,460 points
797 views
0 votes
1 answer

How to find the first field from a file in Bash Shell?

Hi@akhtar, You can extract text from a file. ...READ MORE

answered Oct 20, 2020 in Linux Administration by MD
• 95,460 points
1,207 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Adding yes/no/cancel prompts in shell script

You can use the read command. Here's ...READ MORE

answered Mar 13, 2019 in Linux Administration by ajs3033
• 7,300 points
4,347 views
0 votes
1 answer

How to change the default shell in Linux?

1. Change the password file directly for ...READ MORE

answered May 24, 2019 in Linux Administration by Upasana
• 8,620 points
1,103 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP