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.
collect-info | tee snapshot.txtCorrect. 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.
collect-info >> snapshot.txtIncorrect. >> 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 / 一時ファイル
- Use temporary files and harmless commands for stream experiments.
- Shell redirection syntax and xargs behavior should be checked on the target shell implementation.
Foundation review
Place the operation
tee is a stream splitter; it does not replace the upstream command with a second execution.
Check the side effect
Inspect the screen output and the temporary file for identical data.