Display collect-info output in the terminal while replacing snapshot.txt with the same data.
Split the stream to two destinations.
Which command is appropriate?
tee duplicates standard input to standard output and a file, so the data remains visible and is stored at the same time.
Detailed explanation
collect-info > snapshot.txtIncorrect. > sends output only to the file.
Incorrect. > sends output only to the file.
collect-info | tee snapshot.txtCorrect. collect-info | tee snapshot.txt displays the output and writes the file.
Correct. collect-info | tee snapshot.txt displays the output and writes the file.
collect-info | cat snapshot.txtIncorrect. cat reads a file and does not provide the requested tee split.
Incorrect. cat reads a file and does not provide the requested tee split.
collect-info >> snapshot.txtIncorrect. >> appends only and does not preserve a terminal copy.
Incorrect. >> appends only and does not preserve a terminal copy.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); screen=$(printf 'snapshot\n' | tee "$tmp"); printf '%s/%s\n' "$screen" "$(cat "$tmp")"; rm -f "$tmp"Expected result
snapshot/snapshotKey points
- tee splits a stream
- The default file mode overwrites
- stdout can continue to another pipe
Notes
- Environment: GNU coreutils 9.x / 一時ファイル
- 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.