time estimating within “time” shell command

In case if you need to get data how long your bash script or command takes time you could use variations of the “time” command

for example, some shell script probably take not a certain predicted time due to that execution

so, we have store this duration to file too

$ { time ./pingtest.sh; } 2> out.txt && less out.txt
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=56 time=4.82 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=56 time=4.82 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=56 time=4.81 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 4.819/4.824/4.828/0.056 ms
real 0m2.009s
user 0m0.002s
sys 0m0.000s
real 0m2.011s
user 0m0.003s
sys 0m0.000s
out.txt (END)

where timertest.sh is

$ less pingtest.sh
!/bin/bash
ping 8.8.8.8 -c 3
pingtest.sh (END)

but this sample of time command not quite full, some of other of are there:

$ (time ./pingtest.sh) &> out.txt && less out.txt
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=56 time=4.82 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=56 time=4.89 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=56 time=4.83 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 4.823/4.849/4.890/0.029 ms
real 0m2.012s
user 0m0.003s
sys 0m0.000s
out.txt (END)

reliable links:
https://linux.die.net/man/1/time
https://linux.die.net/man/3/stdout
https://linux.die.net/man/3/stdout

Have You More questions? Please be free to ask us your questions in the
Dzhumaiev.Slack.com channel 🙂