Questions tagged [tee]

For questions related to Linux syscall and a user program that duplicates the contents of a pipe. For security frameworks, use the tags [trusted-execution-environment] or [op-tee].

Introduction

The tee command reads from standard input and writes to standard output and files.

Examples of writing standard output include:

# print output of ps to a file
$ ps aux | tee ps_aux.txt

Using tee with sudo command

$ echo 'foo' >> file 
zsh: permission denied: file

As part of a pipe, tee can take the input and elevate permissions

$ echo "foo" | sudo tee -a file 

Links

How do I “tee” variable number of times in a bash “for loop”?

Linux and Unix tee command

536 questions
22
votes
3 answers

How can I compose output streams, so output goes multiple places at once?

I'd like to compose two (or more) streams into one. My goal is that any output directed to cout, cerr, and clog also be outputted into a file, along with the original stream. (For when things are logged to the console, for example. After closing,…
GManNickG
  • 494,350
  • 52
  • 494
  • 543
20
votes
9 answers

'tee' and exit status

Is there an alternative to tee which captures standard output and standard error of the command being executed and exits with the same exit status as the processed command? Something like the following: eet -a some.log -- mycommand --foo…
pachanga
  • 3,003
  • 4
  • 30
  • 45
20
votes
7 answers

Unix: How can I prepend output to a file?

Specifically, I'm using a combination of >> and tee in a custom alias to store new Homebrew updates in a text file, as well as output on screen: alias bu="echo `date "+%Y-%m-%d at %H:%M"` \ >> ~/Documents/Homebrew\ Updates.txt && \ brew…
Henrik
  • 2,421
  • 4
  • 25
  • 33
19
votes
5 answers

How to redirect stdout+stderr to one file while keeping streams separate?

Redirecting stdout+stderr such that both get written to a file while still outputting to stdout is simple enough: cmd 2>&1 | tee output_file But then now both stdout/stderr from cmd are coming on stdout. I'd like to write stdout+stderr to the same…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
17
votes
4 answers

Get exit code from subshell through the pipes

How can I get exit code of wget from the subshell process? So, main problem is that $? is equal 0. Where can $?=8 be founded? $> OUT=$( wget -q "http://budueba.com/net" | tee -a "file.txt" ); echo "$?" 0 It works without tee, actually. $> OUT=$(…
17
votes
4 answers

tee with utf-8 encoding

I'm trying to tee a server's output to both the console and a file in Powershell 4. The file is ending up with a UTF-16 encoding, which is incompatible with some other tools I'm using. According to help tee -full: Tee-Object uses Unicode enocding…
Angus
  • 505
  • 3
  • 12
17
votes
4 answers

use tee command to redirect output to a file in a non-existent dir

I am trying to use the tee command to redirect output to a file, and I want the file to be created in a dir which is yet to be created. date | tee new_dir/new_file when new_dir is not there, the tee command fails saying tee: new_dir/new_file: No…
comatose
  • 1,952
  • 7
  • 26
  • 42
16
votes
3 answers

itertools.tee on a coroutine?

I have a tree structure of objects. I need to iterate over all the items ("values") in the leaves. For this I'm currently using generator methods as illustrated below: class Node(object): def __init__(self): self.items = [Leaf(1),…
Brecht Machiels
  • 3,181
  • 3
  • 25
  • 38
16
votes
1 answer

tee stdout and stderr to separate files while retaining them on their respective streams

I'm trying to write a script the essentially acts as a passthru log of all the output created by a (non-interactive) command, without affecting the output of the command to other processes. That is to say, stdout and stderr should appear the same…
Michael
  • 9,060
  • 14
  • 61
  • 123
15
votes
4 answers

Is the result of itertools.tee() thread-safe (Python)

Suppose I have this Python code: from itertools import count, tee original = count() # just an example, can be another iterable a, b = tee(original) The question is, will there be any problem if I start iterating "a" in one thread and, at the…
dan19
  • 283
  • 1
  • 8
15
votes
1 answer

PowerShell removing console message colors when using tee-object

Is there any way to stop PowerShell from removing console message colors when using tee-object? When I run without tee-object I get the nice error and verbose powershell message colors like this: powershell.exe -noprofile -file…
DetectiveEric
  • 251
  • 2
  • 12
15
votes
2 answers

Pipe to multiple files, but not stdout

I want to pipe stdout to multiple files, but keep stdout itself quiet. tee is close but it prints to both the files and stdout $ echo 'hello world' | tee aa bb cc hello world This works but I would prefer something simpler if possible $ echo 'hello…
Zombo
  • 1
  • 62
  • 391
  • 407
14
votes
6 answers

bash tee remove color

I'm currently using the following to capture everything that goes to the terminal and throw it into a log file exec 4<&1 5<&2 1>&2>&>(tee -a $LOG_FILE) however, I don't want color escape codes/clutter going into the log file. so i have something…
Andrew Sohn
  • 675
  • 1
  • 6
  • 15
14
votes
8 answers

Unix: confusing use of the 'tee' command

The manual states that tee is a "pipe fitting"-tool. The cases [1] confuse me: 1. case echo "foo bar" | sudo tee -a /path/to/some/file 2. case :w !sudo tee % It is hard to understand the logic of tee from the cases. How does tee work?
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
14
votes
3 answers

How can I split and re-join STDOUT from multiple processes?

I am working on a pipeline that has a few branch points that subsequently merge-- they look something like this: command2 / \ command1 command4 \ / command3 Each command writes to STDOUT and…
Peter
  • 1,983
  • 1
  • 12
  • 9
1
2
3
35 36