Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why time command in linux has different output when I type it in shell than I use it in script?

Tags:

linux

bash

time

The problem is when I use time in shell I get output like that:

1.350u 0.038s 0:01.45 95.1%     0+0k 0+72io 1pf+0w

And when Im using it in script I get:

real    0m1.253s
user    0m1.143s
sys     0m0.047s

I mean why? And in shell script at the beginning I write:

#!/bin/bash
like image 232
l245c4l Avatar asked Sep 07 '25 22:09

l245c4l


1 Answers

Bash has a built-in command time, and your system should also have a separate binary at /usr/bin/time:

$ help time
time: time [-p] pipeline
    Report time consumed by pipeline's execution.

    Execute PIPELINE and print a summary of the real time, user CPU time,
    ...
$ which time
/usr/bin/time

The two commands produce different outputs:

$ time echo hi
hi

real    0m0.000s
user    0m0.000s
sys 0m0.000s
$ /usr/bin/time echo hi
hi
0.00user 0.00system 0:00.00elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+199minor)pagefaults 0swaps
like image 129
Mark Rushakoff Avatar answered Sep 09 '25 23:09

Mark Rushakoff