0
0
Linux CLIscripting~15 mins

tee for splitting output in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Using tee to Split Command Output
📖 Scenario: You are working on a Linux system and want to save the output of a command to a file while also seeing it on the screen. This is useful when you want to keep a record of what you see without losing the live view.
🎯 Goal: Learn how to use the tee command to split the output of a command so it is both saved to a file and displayed on the terminal.
📋 What You'll Learn
Create a file with some sample text
Use the tee command to save and display output
Understand how to append output to a file using tee
💡 Why This Matters
🌍 Real World
System administrators and developers often need to save logs or command outputs while still monitoring them live on the terminal.
💼 Career
Knowing how to use tee helps in debugging, logging, and monitoring scripts or commands in real time, a common task in IT and DevOps roles.
Progress0 / 4 steps
1
Create a sample text file
Create a file called sample.txt with the exact content: Hello World
Linux CLI
Need a hint?

Use the echo command with redirection > to create the file.

2
Use tee to save and display output
Use the command cat sample.txt | tee output.txt to display the content of sample.txt and save it to output.txt at the same time.
Linux CLI
Need a hint?

The tee command reads from standard input and writes to standard output and files.

3
Append output to the file using tee
Use the command echo "Goodbye" | tee -a output.txt to append the text Goodbye to output.txt and display it on the screen.
Linux CLI
Need a hint?

Use the -a option with tee to append instead of overwrite.

4
Display the final content of output.txt
Use the command cat output.txt to display the full content of output.txt.
Linux CLI
Need a hint?

The file output.txt should contain both lines.