Difficulty: Easy
Correct Answer: tee
Explanation:
Introduction / Context:
Sometimes you need to both see command output on the screen and save it to a file for later analysis. Instead of running the pipeline twice or redirecting and then catting, Unix provides a filter that duplicates the stream transparently to multiple outputs.
Given Data / Assumptions:
Concept / Approach:
The 'tee' command splits its standard input and writes it to both standard output and one or more files. Common options include '-a' to append instead of overwrite. 'tee' is ideal for logging build processes, capturing diagnostic streams, or auditing scripts while maintaining interactive visibility.
Step-by-Step Solution:
Verification / Alternative check:
Run a pipeline such as 'dmesg | tee dmesg.txt' and confirm that output appears on screen and that the file contains identical content afterwards.
Why Other Options Are Wrong:
Common Pitfalls:
Overwriting a file unintentionally without '-a', forgetting to redirect stderr separately if needed (use '2>&1' before tee), or misplacing 'sudo' which can change which side of the pipe has elevated permissions.
Final Answer:
tee
Discussion & Comments