[clug] Redirect time command output to file

Sam Couter sam at couter.id.au
Thu May 27 15:42:47 MDT 2010


Hal <hal.ashburner at gmail.com> wrote:
> $ time echo "foo" 2>&1 >>output.log
> happily appends "foo" to output.log but still spits out the time
> output on the terminal. This suggests to me there's a magic third
> output file handle. In addition to stdout & stderr there is stdshell
> or something this? Or am I missing something concerning redirection
> here?

Yes. Redirections are processed in order. You have said "redirect stderr
to stdout and stdout to output.log". stderr still goes to stdout, not
output.log.

You want:

time echo foo >> output.log 2>&1

Which says "redirect stdout to output.log and stderr to where stdout is
now going".

Although somebody else has pointed out something special about the time
built-in that I didn't know and apparently what I've just told you won't
work anyway. It will work with other commands though.

> Ok Invoke the time binary explicitly
> 
> /usr/bin/time --append -o logfile.log /path/to/timed/command 2>&1 >>
> logfile.log
> Seems to work.

And that's how you get around a bash built-in when you want to use the
real thing, although your redirection is still the wrong way around.
-- 
Sam Couter         |  mailto:sam at couter.id.au
OpenPGP fingerprint:  A46B 9BB5 3148 7BEA 1F05  5BD5 8530 03AE DE89 C75C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/linux/attachments/20100528/0a377797/attachment.pgp>


More information about the linux mailing list