Questions tagged [tee]

tee is a command line utility that reads the standard input and writes to the standard output as well as a file specified as an argument. Use this tag for questions about the tee command.

tee is a standard utility that reads from standard input and writes the same output to standard output and files given on the command line.

Example

Taking simple file as this:

$ cat file
AAA
AAAA
AAAAA

These commands will count the rows in the file and write it in file_tee. If file_tee is not empty the contents would be truncated.

$ wc -l file | tee file_tee
3 file

Further reading

221 questions
83
votes
7 answers

how to redirect output to multiple log files

How to redirect standard output to multiple log files? The following does not work: some_command 1> output_log_1 output_log_2 2>&1
doubledecker
  • 1,807
  • 3
  • 15
  • 12
52
votes
2 answers

Using exec and tee to redirect logs to stdout and a log file in the same time

In a bash script, how can I redirect all standard outputs to a log file and tee the output on the screen using exec ? log_file="$HOME/logs/install.txt-`date +'%Y-%m-%d_%H-%M-%S'`" [ -f "$log_file" ] || touch "$log_file" exec 1>> $log_file 2>&1 This…
4m1nh4j1
  • 1,823
  • 8
  • 29
  • 40
47
votes
3 answers

Direct output to pipe and stdout

Is there a way to pipe the output of a command and direct it to the stdout as well? So for example, fortune prints a fortune cookie to stdout and also pipes it to next command: $ fortune | tee >(?stdout?) | pbcopy "...Unix, MS-DOS, and Windows NT…
user14492
  • 753
  • 1
  • 8
  • 15
46
votes
7 answers

using tee to output intermediate results to stdout instead of files

I know that to capture a pipeline's contents at an intermediate stage of processing, we use tee as ls /bin /usr/bin | sort | uniq | tee abc.txt | grep out , but what if i don't want to redirect the contents after uniq to abc.txt but to…
Aman
  • 1,013
  • 2
  • 10
  • 18
35
votes
4 answers

Output to stdout and at the same time grep into a file

I have a script that outputs text to stdout. I want to see all this output in my terminal, and at the same time I want to filter some lines and save them in a file. Example: $ myscript Line A Line B Line C $ myscript | grep -P 'A|C' > out.file $…
lorenzo-s
  • 596
  • 1
  • 8
  • 10
35
votes
3 answers

How does `:w !sudo tee %` work

If you open a file that you don't have permission to write to in vim, then decide you need to change it, you can write your changes without exiting vim by doing :w !sudo tee % I don't understand how this can work. Can you please dissect this? I…
Ali
  • 6,693
  • 6
  • 32
  • 37
30
votes
2 answers

Why does 'ping' not output a summary when redirecting output?

I can ping google.com for several seconds and when I press Ctrl + C, a brief summary is displayed at the bottom: $ ping google.com PING google.com (74.125.131.113) 56(84) bytes of data. 64 bytes from lu-in-f113.1e100.net (74.125.131.113): icmp_seq=2…
ks1322
  • 1,646
  • 15
  • 26
23
votes
4 answers

tee + cat: use an output several times and then concatenate results

If I call some command, for instance an echo I can use the results from that command in several other commands with tee. Example: echo "Hello world!" | tee >(command1) >(command2) >(command3) With cat I can collect the results of several commands.…
Trylks
  • 383
  • 1
  • 2
  • 9
22
votes
3 answers

tee stdout to stderr?

I'd like to send stdout from one process to the stdin of another process, but also to the console. Sending stdout to stdout+stderr, for instance. For example, I've got git edit aliased to the following: git status --short | cut -b4- | xargs gvim…
Roger Lipscombe
  • 1,670
  • 1
  • 20
  • 34
21
votes
4 answers

Is it possible to redirect the output of a command into more than one command?

As far as I know, I can use the tee command to split the standard output onto the screen and further files: command -option1 -option2 argument | tee file1 file2 file3 Is it possible to redirect the output to commands instead of files using tee, so…
Abdul Al Hazred
  • 25,760
  • 23
  • 64
  • 88
20
votes
3 answers

Use sudo tee with heredoc to append to existing file

From Generate script in bash and save it to location requiring sudo we have this method, which I like: sudo tee "$OUTFILE" > /dev/null <<'EOF' foo bar EOF However, I would like to use that approach to append to an existing file $OUTFILE. The above…
MountainX
  • 17,168
  • 59
  • 155
  • 264
20
votes
2 answers

Is there any difference between tee and >> when using echo?

Is there any difference beteween doing: echo "hahaha" >> file1 and echo "hahaha" |tee -a file1 ? Yes, I noticed that I cannot write to write protected files even aith sudo echo, but I can if I sudo tee. Thanks.
iamAguest
  • 483
  • 1
  • 6
  • 17
20
votes
2 answers

How to terminate Linux tee command without killing application it is receiving from

I have a bash script that runs as long as the Linux machine is powered on. I start it as shown below: ( /mnt/apps/start.sh 2>&1 | tee /tmp/nginx/debug_log.log ) & After it lauches, I can see the tee command in my ps output as shown below: $ ps |…
PhilBot
  • 69
  • 8
  • 22
19
votes
3 answers

Why does `echo 'hi' | tee > a b c` create multiple files, whereas `echo 'hi' > a b c` doesn't?

My env: zsh, macOS Command in concern: echo 'hi' | tee > a b c echo 'hi' > a b c Command 1 creates files named a, b and c with content hi. Command 2 creates a file named a with content hi b c. AFAIK, only the usage of Command 1 without > is…
catwith
  • 293
  • 2
  • 8
18
votes
2 answers

`tee` for commands

tee can redirect the piped standard input into the standard output and file. echo Hello, World! | tee greeting.txt The command above would display the greeting on the terminal screen and save it in the contents of greeting.txt file, creating the…
user86041
1
2 3
14 15