Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: Calculate how long it takes a script to run

Tags:

bash

Is there a way to have a bash script to print how long it took to run?

Something fairly simple like:

#!/bin/bash
something to start time
command to be run
something to calculate runtime and print result
like image 210
CRYPTODOOM Avatar asked Nov 01 '25 17:11

CRYPTODOOM


2 Answers

There is the standard tool time.

The script:

#!/bin/bash

echo start
sleep 2
echo end

Usage:

$ time ./so.sh       
start
end
./so.sh  0.00s user 0.01s system 0% cpu 2.007 total

You can use the time command:

time - run programs and summarize system resource usage

For example:

time <command>

Will give you the execution time of your commands

like image 22
Avihoo Mamka Avatar answered Nov 04 '25 09:11

Avihoo Mamka