tee
tee is like a T-shaped water pipe: the same water flows both to a bucket and onward to the next place. You save the output to a file and still see it on screen.
In this page:
Syntax
command | tee file_name
command | tee -a file_name
tee
tee reads from standard input and writes it both to a file and back out to standard output simultaneously, letting you save output to a log while still seeing it in your terminal.
It's often placed in the middle of a pipeline. tee -a appends to the file instead of overwriting it.
Note:
Use
command | tee log.txt to view output live while also saving it for later.Example: tee
#!/bin/bash
echo "Important message" | tee log.txt
echo "--- contents of log.txt ---"
cat log.txt
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Forgetting
-a, sotee fileoverwrites the file each time. - Expecting
teeto write errors, when it only copies standard output. - Using
sudo cmd > fileand expecting the redirect to have root rights; usecmd | sudo tee file.
🔒
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: