Here's my command:
(time ( \
time sleep 1; \
time sleep 2 \
) 2>&1 | tee inner.txt ) 2>&1 | tee outer.txt
cat inner.txt
shows:
real 0m1.003s
user 0m0.001s
sys 0m0.002s
real 0m2.003s
user 0m0.001s
sys 0m0.002s
and cat outer.txt
shows:
real 0m1.003s
user 0m0.001s
sys 0m0.002s
real 0m2.003s
user 0m0.001s
sys 0m0.002s
real 0m3.068s
user 0m0.005s
sys 0m0.008s
How can I get just this into outer.txt
?:
real 0m3.068s
user 0m0.005s
sys 0m0.008s
Even better, how can I get inner.txt
, outer.txt
, and both.txt
, where both.txt
would contain:
real 0m1.003s
user 0m0.001s
sys 0m0.002s
real 0m2.003s
user 0m0.001s
sys 0m0.002s
real 0m3.068s
user 0m0.005s
sys 0m0.008s
Note that the time
cmd I'm using above is the bash built-in function time
, not the /usr/bin/time
command, which I learned about through my question here: How to pass optional arguments to time
command
I'm on Linux Ubuntu 18.04.
This question is a follow-up to my answer here, in order to try to improve that answer: How to time a multiline, multi-subcommand command in bash, and optionally store all output into a file
tee
prints to a file andstdout
- use output redirection instead in the inner part if you don't want the inner output inouter.txt
.