skip to content
Alvin Lucillo

Write to both stdout and file

/ 1 min read

If you want your data from standard input (stdin) to be both written to standard output (stdout) and a file, use tee.

In the example below, ls -l output is written into stdout and output.text file.

ls -l | tee output.txt
total 780
-rw-r--r--   1 user1 user1   1071 May 11  2024 LICENSE
-rw-r--r--   1 user1 user1  12213 May 11  2024 README.md

cat output.txt
total 780
-rw-r--r--   1 user1 user1   1071 May 11  2024 LICENSE
-rw-r--r--   1 user1 user1  12213 May 11  2024 README.md