> sends output to a file, and you see nothing. Sometimes you want both: see the output and save it. tee does this.
grep WARN shop.log
tee warnings.txt
stdout
Terminal
tee writes each line it reads to the file and to its standard output:
text
learner@tidepool:~$ grep WARN shop.log | tee warnings.txt
12:20 WARN low stock: cake
learner@tidepool:~$ cat warnings.txt
12:20 WARN low stock: cakeIn the middle of a pipeline
Because tee writes to standard output, the pipeline can continue. Save the lines, then count them:
text
learner@tidepool:~$ grep ERROR shop.log | tee errors.txt | wc -l
2Add to the file: -a
| Line | The file |
|---|---|
tee FILE | Emptied first, like > |
tee -a FILE | Added to, like >> |