Today I struggled with time.
I wanted to use it in a bash script, so I checked the man page, where I found interesting things :
$ 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 built 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 example line from the man page to understand how it works :
$ time -f "%E real,%U user,%S sys" ls -Fs
-su: -f: command not found
wtf??! The example line doesn’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! But it was stupid…
Just to remember, when using the bash time, to 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