How to Use the tee Command in Linux: Step-by-Step Guide
HardReset.InfoDecember 31, 20256 min14 views
2 connectionsΒ·4 entities in this videoβUnderstanding the tee Command
- π‘ The tee command in Linux is used to display output on the terminal while simultaneously writing that same output to one or more files.
- π― It's incredibly useful when you need to see command results in real-time and also preserve them for later review.
Basic Usage and Overwriting
- π To use
tee, you typically pipe the output of another command into it, followed by the desired filename (e.g.,ls | tee output.txt). - β οΈ By default,
teewill overwrite the content of the specified file if it already exists. - π For example, piping
echo hellototee file.txtwill result infile.txtcontaining only 'hello'.
Appending Output with tee -a
- β To append output to a file instead of overwriting it, use the
-aoption (e.g.,echo next line | tee -a file.txt). - π This ensures that new output is added to the end of the file, preserving previous content.
Writing to Protected System Files with sudo tee
- π When you need to write to protected system directories (like
/etc/), you can usesudo tee. - βοΈ The syntax
echo test | sudo tee /etc/test.confallows you to write content to system files after entering your password.
Writing to Multiple Files and Saving Disk Usage
- ποΈ The
teecommand can write output to multiple files simultaneously by listing them after the command (e.g.,ls | tee file1.txt file2.txt). - π A practical example is saving disk usage information using
df -h | tee disk-usage.txt, which displays the output and saves it todisk-usage.txt.
Knowledge graph4 entities Β· 2 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover Β· drag to explore
4 entities
Chapters3 moments
Key Moments
Transcript25 segments
Full Transcript
Topics11 themes
Whatβs Discussed
tee commandLinuxLinux CommandsTerminalPipesFile AppendingFile Overwritingsudo teeSystem FilesDisk UsageCommand Output
Smart Objects4 Β· 2 links
ProductsΒ· 3
ConceptΒ· 1