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 :
[cc lang=”bash”]$ 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
[…][/cc]
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
0:00.20[/cc]
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
0m2s[/cc]
and in seconds only :
[cc lang=”bash”]$ TIMEFORMAT=$’%0R’
$ time wget -q –timeout=60 –connect-timeout=60 -O – ‘http://my-url’ >>/dev/null
2[/cc]
😀