Consider the following Bash command lines:
time ls # Sends directory contents to stdout
time ls --foo # Sends an error message to stderr (--foo is an invalid option)
Redirecting the outputs (normal output and error output) of time to one file and the outputs of ls to another file:
time ( ls &>ls.txt ) &>time.txt
time ( ls --foo &>ls.txt ) &>time.txt
Redirecting error output of time to time.txt and sending the outputs of ls to terminal:
time ( ls &>/dev/stdout ) 2>time.txt
time ( ls --foo &>/dev/stdout ) 2>time.txt
The above two lines combine the normal output and the error output of ls into stdout (fd 1). I would like to do the following: send the outputs of ls to the terminal (normal output to stdout, error output to stderr), and the error output of time to time.txt. Conceptually:
time ( ls 1>/dev/stdout 2>/dev/stderr ) 2>time.txt
time ( ls --foo 1>/dev/stdout 2>/dev/stderr ) 2>time.txt
Unfortunately, the last line isn’t working properly because the error output of ls gets written into time.txt.
How to send the normal output of ls to the stdout, the error output of ls to stderr, and the error output of time to time.txt?
This might work for you: