Reputation: 73
I'd like to redirect the time of a process to a file, and the process itself redirects to a file. Here's what I've tried:
time &> ltime.txt echo | ls -l > ls-l.txt
Both files (ltime.txt
and ls-l.txt
) are created, but ltime.txt
is empty.
time
still outputs to the screen,
which is fine in my case,
but I expected it to not do that because of the &>
:
real 0m0.034s
user 0m0.000s
sys 0m0.004s
(All that I know about this came from http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html)
Any suggestions?
Upvotes: 2
Views: 68
Reputation: 4353
Maybe you're getting bitten by the time
that's built-in to the shell? Try this:
/usr/bin/time ls -l > ls-l.txt 2> ltime.txt
From man time
:
Users of the bash shell need to use an explicit path in order to run
the external time command and not the shell builtin variant.
[Updated to add]
Apparently the location of time
isn't totally standard. For a one-off use (and for general info) which time
will tell you where it is. For a portable script you can say command time ...
. (command
is a shell built-in that tells the shell to ignore built-ins.)
Upvotes: 1
Reputation: 59310
Try
{ time ls -l > ls-l.txt ; } &> ltime.txt
The curly braces capture the output even with the builtin.
Upvotes: 1