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 :

[cc lang=”bash”]$ man time
time – run programs and summarize system resource usage

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

-o FILE, –output=FILE
-f FORMAT, –format FORMAT

Ok great. So I wrote my command like this :

[cc lang=”bash”]$ time -f %E wget -q –timeout=60 –connect-timeout=60 -O – ‘http://my-url’ >>/dev/null
-su: -f: command not found[/cc]

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

[cc lang=”bash”]$ time -f “%E real,%U user,%S sys” ls -Fs
-su: -f: command not found[/cc]

wtf??! The example given didn’t work either !
And then
[cc lang=”bash”]$ time –help
-su: –help: command not found[/cc]

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 :
[cc lang=”bash”]$ /usr/bin/time -f %E wget -q –timeout=60 –connect-timeout=60 -O – ‘http://my-url’ >>/dev/null
Finally! It was just a silly thing…

Just remember, when using the bash time, get the time in minutes/seconds:
[cc lang=”bash”]$ TIMEFORMAT=$’%0lR’
$ time wget -q –timeout=60 –connect-timeout=60 -O – ‘http://my-url’ >>/dev/null

and in seconds only :
[cc lang=”bash”]$ TIMEFORMAT=$’%0R’
$ time wget -q –timeout=60 –connect-timeout=60 -O – ‘http://my-url’ >>/dev/null


Comments are closed.
Praesent elementum tempus at eleifend libero.