Save run-job's standard output to output.log.
Save standard error to errors.log, overwriting both existing files.
Which command is correct?
Using > and 2> on one command independently redirects standard output and standard error to separate files.
Detailed explanation
run-job > output.log 2> errors.logCorrect. Standard output and standard error each receive their own file destination.
Correct. Standard output and standard error each receive their own file destination.
run-job > output.log 2>&1Incorrect. 2>&1 merges standard error into standard output rather than separating the files.
Incorrect. 2>&1 merges standard error into standard output rather than separating the files.
run-job 2> output.log > errors.logIncorrect. It sends standard error to output.log and standard output to errors.log, reversing the requirements.
Incorrect. It sends standard error to output.log and standard output to errors.log, reversing the requirements.
run-job | output.log | errors.logIncorrect. Pipes require commands, not filenames as standalone stages.
Incorrect. Pipes require commands, not filenames as standalone stages.
Try it yourself
An example you can run in a temporary verification environment.
bash -c 'printf OUT; printf ERR >&2' > /tmp/kp-out.log 2> /tmp/kp-err.log; paste -d, /tmp/kp-out.log /tmp/kp-err.log; rm /tmp/kp-out.log /tmp/kp-err.logExpected result
OUT,ERRKey points
- > redirects FD 1
- 2> redirects FD 2
- The destinations can be independent
Notes
- Environment: Bash 5.2
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.