Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
1answer
109 views

Process substitution and redirection using tee

Suppose that you redirect, in bash, the standard output of a command cmd to a file named f.out, and the standard error to f.err, using tee to preserve console printing: cmd 1> >(tee f.out) 2>...
2
votes
1answer
48 views

Combine brace and variable expansion in one line

I would like to have a logging function that takes filenames as arguments and replicate the stdout to all of these files. This is what I have come up so far: function logger() { exec > >(...
3
votes
3answers
113 views

tee into different variables

From the bash code command1 | tee >(command2) | command3 I want to capture the output of command2 in var2 and the output of command3 in var3. command1 is I/O-bound and the other commands are ...
1
vote
1answer
43 views

Inject string in tee output

I am using pipelines to implement some functionality with bash on Centos 6. During these pipes I want to export my data in a log file, but this data comes from different pipes in my pipeline and I ...
2
votes
2answers
41 views

Forward pg_dump to 2 different psql, one log file but not the console

I am trying to push the pg_dump to 2 psql and to a log file but I don't want to add noise to my terminal. Following the numerous post of the tee tool, I reached this command which is indeed working ...
2
votes
1answer
88 views

Redirect script output both to console and to log

Take a look on the following # more /tmp/myscript #!/bin/bash echo I AM echo BIG GUY echo AND ALSO SMART # bash /tmp/myscript | tee -a >/tmp/log why we not get the output from echo in the ...
0
votes
1answer
77 views

Bash output redirection to new file each time command is run

I have a Bash one-liner that redirects the output of a command to a new, fresh file each time the command is run. Logging the output of each time the command is run is important (I'm using ls here as ...
-1
votes
2answers
211 views

Tee does not write to file when combined to pipe

I'm trying to run a C code with matlab, developed by others. In c, it's written to stdout, then in matlab a pipe is created and read: unix('rm -f /tmp/matdata.in;mkfifo /tmp/matdata.in'); unix(['./',...
2
votes
3answers
76 views

tee sends incomplete data

$ head -c10G /dev/zero | tee >(head -c1M | wc -c) >(head -c10M | wc -c) >(head -c100M | wc -c) >(head -c1000M | wc -c) gives: 1048576 1064960 1064960 1064960 I would have expected: ...
0
votes
0answers
41 views

Logging output of scripts called inside another script

Inside bashscript, I am using exec and tee to redirect logs to stdout and a log file in the same time - Unix & Linux Stack Exchange. exec &> >(tee -a "${LogFile}") I am sourcing ...
1
vote
1answer
146 views

Explanation of unpredictable behaviour of tee

I encountered a behaviour that I don't understand while testing a script that sums the outputs from repeated executions of a program. To reproduce it create the text files out, which represents the ...
0
votes
1answer
308 views

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 ...
1
vote
3answers
372 views

How to grep from tee?

I want to check wether the output of my command contains "rerun" (and then rerun) but I also want to display the whole output. I know that I could use one of these: command | tee >(grep rerun) ...
-2
votes
1answer
75 views

What is the difference (if any) between “cat input | tee > output” and “tee < input > output”?

I obtained the following: $ time $(tee < infile > outfile) real 0m14.721s user 0m0.094s sys 0m2.629s $ time $(cat infile | tee > outfile) real 0m8.931s user 0m0.123s sys 0m3.168 Is that ...
1
vote
1answer
230 views

Print and log stdout and stderr in fish shell

I am using the fish shell and try to log stdout and stderr into two separate files and printing them in the terminal at the same time (e.g., by piping each stream to tee). In bash I would do (see ...
0
votes
1answer
76 views

Redirecting stdout and stderr when installing software

I would like to be able to simply save stdout and stderr when installing software There are 3 scenarios I would like to address: When using apt-get When using apt-get and tee When using make install ...
1
vote
1answer
48 views

Send stderr to a different receiver in pipe

Right now I have this: echo "$run_test" | bash 2>&1 | prepend "r2g-test:" "yellow"; What this does is prepend "r2g-test:" to each line of the stdout/stderr. Because I am sending stderr to ...
1
vote
1answer
138 views

Send find's output to stdout and piped to grep

I have a 100+ rar files which I want to extract using find's exec command. I'd like to see the usual rar output so I can monitor its progress, and also to pipe the output to grep and then on to wc to ...
1
vote
1answer
385 views

How to output SSH commands that are being sent to a server

I have a script that connect to a Network device. It runs some commands and basically I want to output the SSH commands that are being executed. To make myself clearer, I connect to one device, ...
0
votes
1answer
242 views

overwrite file and echo to stdout

I have a simple bash function to increment a number and store it in a file: get_next_int (){ my_file="$HOME/next_int.json" touch "$my_file" typeset -i my_num=$(cat "$my_file") echo "$((++...
0
votes
2answers
601 views

hide output of command while using cat and tee

I have a text file that contains some IPs. I want to copy the contents of this text file into /etc/ansible/hosts without showing the output on the terminal (as shown in example 2). Note: root user is ...
0
votes
1answer
55 views

response checker in a script

I have following response checker in a script: #!/bin/bash test_fn() { WARNFILE=$1 echo echo "--- BEGIN ---" cat ${WARNFILE} echo "--- END ---" echo while true; do read -r -n 1 -p "Continue? [y/...
0
votes
1answer
317 views

Writing user input to file using tee

I have a script which guides users through the installation of my software and I want to write a log file in case something bad happens and the user needs support. The script looks like this: while ...
1
vote
1answer
235 views

Read stdin and pass through pipeline to tee

I'm playing around with xinput to watch keyboard events. I'd like to transform the output with awk and pass it to tee, printing to stdout and writing to a file simultaneously. I watch events on ...
0
votes
0answers
288 views

scripting with telnet and tee

with #!/bin/bash telnet ipaddr port & i=1 while [ "$i" -lt 3 ] do (( i += 1 )) sleep 10 done result: Trying ipaddr... Connected to ipaddr. Escape character is '^]'. ...
1
vote
1answer
77 views

stdout to multiple files, if stdout to file by default

1. Summary I don't find, what can I do, that text output to multiple files, if by default in CLI program stdout to file. 2. Example I use generate-changelog package. In this package by default ...
1
vote
2answers
296 views

Redirection and piping for grepping

I'm working on a script that will run a checksum process which outputs to STDOUT, which I then want to grep for lines matching OK, or FAILED and do different things with those matches (i.e. output to ...
3
votes
1answer
74 views

non-deterministic output from independent processes run concurrently by process substitution

On bash v4.1.2(2), the following simple statement, chosen merely as a minimal example demonstrating the problem, gives seemingly random output: $ for n in {0..1000}; do echo "$n"; done | tee >(...
18
votes
2answers
2k views

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 ...
0
votes
1answer
41 views

Inconsistent behavior when modifying file in-place with cat, sort, tee, and pipes [duplicate]

Situation: When using the following command: cat foo | sort | tee foo where foo is a text file of multiple lines, the outcome is not consistent. The two outcomes I've observed are: The file is ...
2
votes
2answers
270 views

what is the difference in the syntax to capture the bash output?

I usually use ./aaa.sh 2>&1 | tee -a log But found a new command which seems easier: ./aaa.sh &> log So what am I giving up in the second case?
-1
votes
1answer
153 views

Origin of tee's name

Does anybody know where the tee command-line utility got it's name, I can't seem to find anything.
1
vote
2answers
692 views

How to make any program work with the tee command?

I wrote a program (in Ruby) and it worked well. It prints out a few lines of text and then pause for a minute and then repeats the above. It works well (in Mac OS X's terminal), but I noted that if I ...
3
votes
2answers
277 views

`tee` and `bash` process substitution order

I'd have supposed this code would have printed "oof" first: echo foo | tee >(rev) | ( sleep 1 ; cat ; ) Output: foo oof Increasing the sleep time doesn't change the order. Why doesn't that ...
1
vote
3answers
464 views

Strange output when using tee in pipe command

I had to use the following command in an assignment: who|tee test|wc -l The output on my system is below, which implies that 2 users are connected: 2 Why is it I don't get the output of who on the ...
1
vote
2answers
1k views

How to stdin with tee or other kind of pipes or redirection of outputs? [closed]

Let's say I want to see the output what a command does, such as apt-get. However, if I would run a command redirecting the output such as apt-get install some-application -y > apt_out.txt or apt-...
3
votes
3answers
5k views

pipe password to `sudo` and other data to `sudo`ed command

Both of these commands work: (note the -S in sudo tells sudo to read the password from stdin). echo 'mypassword' | sudo -S tee -a /etc/test.txt &> /dev/null echo -e '\nsome\nmore\ntext' | sudo ...
0
votes
3answers
5k views

How to use tee command with echo as per below requirement?

Appending a variable which contains the tee command and log file name, not getting the expected result, since echo is printing the variable content. Below is the file content, actual output and ...
1
vote
2answers
534 views

How to pipe part of the output matching pattern into the file, leaving the rest to stdout?

Let a.out be the program which produces lots of messages to stdout, e.g.: $ ./a.out A: abc B: xyz A: aaa A: bbb B: zzz C: fff ... What I need is to distinct the output into separate files, one ...
0
votes
1answer
619 views

Get exit code from preceding command before pipe [duplicate]

I have this: node ${SUMAN_RUNNABLE} | tee -a run.sh.log EXIT_CODE=$?; but it looks like the exit code is always 0 because tee is providing the code not the node executable. Is there a way to ...
13
votes
2answers
3k views

`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 ...
6
votes
3answers
1k views

tee -a does not recreate file

I am running the following command on a Raspberry Pi 3 Debian latest release: cat /dev/ttyUSB0 | tee -a /media/pi/KINGSTON/klima.out | grep -F $ | tee -a /media/pi/KINGSTON/log The command works ...
4
votes
1answer
5k views

How does the tee command works? [closed]

After coming across about 3 tee explanations I regard as undidactic, I would ask for a simple, general, and stepped (if possible) explanation about this command, aimed for Linux newcomers. I do ...
0
votes
1answer
31 views

Restarting program running in the background and still make it consume from stdin

This is an extension of previous question I had asked here { python2 readLines.py & python2 readLines.py & python2 readLines.py & python2 readLines.py & python2 readLines.py &...
1
vote
0answers
52 views

Why isn't tee outputting to stdout? [duplicate]

I'm using tmux and cueing up a very large copy: /bin/cp -aRv /mnt/src/folder/. /mnt/dest/folder/ 2>&1 | tee /log/big_copy_log When I run without tee, I see output on the terminal just fine. ...
1
vote
3answers
930 views

Using tee to append string to a file and also use it as replacement for a pattern in another file

I have the following code: cat file | grep example | sed 's/http/https/' >> report.txt Output of that command: https://example.com/page/index.html This will add a link, with HTTPS, to the ...
1
vote
1answer
157 views

Output GCC Version Results to File

When I run gcc -v I'd like to output the results to a text file. I thought something like gcc -v > ~/defaultGCC.txt would store the version output but it does not. I also tried gcc -v | tee ~/...
1
vote
5answers
591 views

using stdout twice (but not tee as I know it)

I have a question related to how to fork stdout in two directions but with a different twist. (I already know about tee! :) I'd like the output both to appear as is (tee to console?) and to be ...
4
votes
3answers
2k views

Bash: Scope of variables in a for loop using tee

Consider: numbers="1 111 5 23 56 211 63" max=0 for num in ${numbers[@]}; do [ $num -gt $max ]\ && echo "old -> new max = $max -> $num"\ && max=$num ...
5
votes
0answers
106 views

How to create a real copy of file descriptor stdout and stderr without using unbuffer / script / tee just with bash built-ins?

My goal is to duplicate, redirect all output (stdout and stderr) of an application (apt-get) to a file while retaining the usual behavior of the application (apt-get), stdout and stderr. How to ...