Time

Time

Today I struggled with the time command.

I wanted to use it in a bash script, so I checked the man page, where I found interesting stuff :

$ man time
time - run programs and summarize system resource usage

SYNOPSIS
time   [ -apqvV ] [ -f FORMAT ] [ -o FILE ]
[ --append ] [ --verbose ] [ --quiet ] [ --portability ]
[ --format=FORMAT ] [ --output=FILE ] [ --version ]
[ --help ] COMMAND [ ARGS ]

[...]
OPTIONS
-o FILE, --output=FILE
-f FORMAT, --format FORMAT
--quiet
[...]


Ok great. So I wrote my command like this :

$ time -f %E  wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
-su: -f: command not found

hm. Maybe I did something wrong. Let’s try the man page’s example to understand how things work :

$ time -f "%E real,%U user,%S sys" ls -Fs
-su: -f: command not found

wtf??! The example given didn’t work either !
And then

$ time --help
-su: --help: command not found

ok… so, searching a little bit further helped me find the explanation :

Your shell (apparently bash) provides a builtin time function. If you want to use time binary, call it by absolute path (/usr/bin/time)

let’s try :

$ /usr/bin/time -f %E  wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
0:00.20

Finally! It was just a silly thing…

Just remember, when using the bash time, get the time in minutes/seconds:

$ TIMEFORMAT=$'%0lR'
$ time wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
0m2s

and in seconds only :

$ TIMEFORMAT=$'%0R'
$ time wget -q --timeout=60 --connect-timeout=60 -O - 'http://my-url' >>/dev/null
2

😀

Comments are closed.
574d9c639a49d1ed5457b5d9d477f61c+++++++++++