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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
41 views

Can I use tee to display output that other utilities tend to suppress?

The macos pbcopy utility grabs its input stream and stores it in the system clipboard, without displaying anything. So, when I want to copy/paste the output of a command in the terminal, I typically ...
JL Peyret's user avatar
  • 103
12 votes
3 answers
2k views

What is the `tee` command in Linux?

I am trying to interpret the following tee command: cat colors.txt words.txt | tee colorsAndWords.txt | wc Is my understanding, as follows, correct? cat colors.txt words.txt: This command ...
Nosail's user avatar
  • 221
2 votes
2 answers
89 views

tee /dev/stderr inside script truncates output file if you redirect stderr

Given a script like below if I try to redirect stderr to a file, then the file is truncated at the point tee is used: $ cat test.sh #!/bin/bash set -eux echo before echo '{ "foo": "...
Jakub Bochenski's user avatar
0 votes
2 answers
58 views

How can I encode a plaintext configuration file then `tee` it into its destination?

I have a vanilla configuration for Nginx (nginx.conf) in plaintext format. It has Latin characters, space indents and is ~250 lines total. I use it when I compile Nginx from source. After the source ...
Pete Cooper's user avatar
0 votes
1 answer
82 views

Piping output to tee breaks the conditional

I am trying to test for the presence of custom firewall-rules on servers. I am doing this by processing the iptables output with awk and returning an appropriate exit-code. This works as intended, and ...
ARMs_for_the_poor's user avatar
0 votes
1 answer
66 views

Breaking command output into new lines instead of refreshing the same line

I'm trying to write a script that involves SnapRAID, where the progress output of snapraid sync is timestamped and logged to both a file and stdout. The issue I am facing is that snapraid sync outputs ...
MrMeeb's user avatar
  • 3
0 votes
0 answers
21 views

Mail remote commands output on failure

I would like to run a command on a remote server and send an email alert (locally) in case of failure. As surprising it is this actually works: ssh -p1222 [email protected] 'cd /root/chk; md5sum -c /root/...
dashy's user avatar
  • 1
0 votes
1 answer
69 views

Shell: Why is there a "duplicate process " on using a pipe and tee?

I'm not very familiar with bash process, and was surprised to see a "duplicate" process running while using pipe and tee. Can you help me understand this? In the following, the path to the ...
Mitch's user avatar
  • 1
0 votes
0 answers
71 views

shell stdout to two command and program is stuck

I have a sample shell command to calculate array percentile number $ time zcat input.txt.gz | head -n 999999 | awk 'BEGIN{FS="\t"}{print $13}' | st --percentile=97.5 75 real 0m3.532s ...
zhang's user avatar
  • 123
0 votes
0 answers
68 views

Using recursive grep on multiple group of words, and output them in different text files

I try to figure out a way to use recursive grep on a group of words, and output the results in different textfiles. My thought was I can do this in my case: grep -r -A 2 -B 2 --include={LIST}.{txt,log}...
carouselcarousel's user avatar
6 votes
2 answers
525 views

Redirect output to one file, while simultaneously filtering output to another using grep

I have a process running that spits out a line of data every second. I want to output all the output to 'output.txt', but also output lines that have @ to a different file 'emails.txt'. I tried ...
SEU's user avatar
  • 219
0 votes
1 answer
101 views

how to exit command without using ctrl + d

I want to open three terminals and I want to write a command in the first window that will send a Hello message to the other two. The command must allow a one-time sending without a response from the ...
bara's user avatar
  • 19
1 vote
1 answer
212 views

Tee remove chars from file and not the console output

I want to output a command's results to both the console and a file. For that, I use tee. But I would also like to remove the ESC character from the file and not from the console output because it ...
Moutabreath's user avatar
0 votes
1 answer
125 views

How to solve 'tee: Too many open files' when trying to redirect output to multiple files

I need to download hundreds of json files from a list of urls stored in a csv. As it would be impossible to do so manually, I wrote a short bash script to read the urls one by one using Python and ...
Francesco Ghizzo's user avatar
0 votes
1 answer
217 views

Trying to rotate logs however tee command fails to return after execution

My logs nohup.out is owned by root user while I m trying to rotate the logs using system which has privileged access using sudo I have written the below script to rotate logs. cat rotatelog.sh cp /var/...
Ashar's user avatar
  • 469
3 votes
2 answers
130 views

Replicate tee behaviour without subshell usage so that variable scope is not affected

I need the capture the output of a command group in BASH to STDOUT and a log file. Consider this code with command grouping and it's output #!/usr/bin/bash main(){ declare -i mycode=1 echo "...
shocko's user avatar
  • 49
0 votes
1 answer
208 views

Using sudo tee in script sends junk to terminal also, bash Debian 11 [duplicate]

I have a command line: # Download and add the Nginx GPG key to verify the authenticity of the packages. wget -O - https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor | sudo tee /usr/share/...
gwhiz's user avatar
  • 3
8 votes
1 answer
636 views

tee is faster than no tee

I have this simple bash script: #!/bin/bash for i in {1..1000000} do echo "hello ${i}" done That prints a message a million times. I try to compare the performance of dumping all the ...
areller's user avatar
  • 181
2 votes
0 answers
36 views

Why does the exec redirection disturb / interrupt a pipe to jq? [duplicate]

This is the reduced version of my script: # parse json echo '[{"foo":"bar"}]' | jq # log output to file and stdout exec &> >(tee -a "/tmp/test.log") # parse ...
mgutt's user avatar
  • 407
0 votes
2 answers
181 views

Clean way to print command used to run script (stdin), stdout and stderr into file

I was attempting to run a script in bash: cc.sh To run the bash script: ../cc.sh ../seq/ seqf where ../seq/ and seqf are both arguments required. I wanted to save the command I used to run the script ...
web's user avatar
  • 193
0 votes
2 answers
256 views

Run 2 Commands, append to file & show command output on console, but of only one command

I am attempting to run a Linux command such as nmap & pass the input into the txt2html command which then appends to a file but also show the output of the nmap command only. The command provided ...
E-Guy's user avatar
  • 3
1 vote
3 answers
725 views

How does tee differ from redirecting/appending?

If we want to copy-paste what we just wrote in stdin to stdout, we can use a redirect > or append >>. How does tee also writing from stdin to stdout different?
kature's user avatar
  • 21
19 votes
3 answers
3k views

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....
catwith's user avatar
  • 293
0 votes
2 answers
269 views

Fork stdin to stdout & stderr?

I am wondering if it's possible to fork standard input to stdout & stderr? Something like this, $ echo "hi" | fork > std.out 2> std.err $ cat std.out hi $ cat std.err hi Or, am I ...
David Streid's user avatar
2 votes
2 answers
2k views

How to use tee to append to start of file, as opposed to last?

I'm using this bash command to append data to a markdown file: echo "${{ env.PR_TITLE }}" | tee -a page1.md. I was wondering if I could append the echo statement to page1.md at the start, so ...
yung peso's user avatar
  • 147
0 votes
1 answer
654 views

How to get color in terminal but no color in output file [duplicate]

To show output in both terminal and to a file, tee can be used like below ls --color=auto | tee opfile But now, there is no color in the terminal. If I force colors, opfile also has colors which ...
balki's user avatar
  • 4,367
0 votes
0 answers
596 views

2>&1 | tee cannot get full output log

I'm using the timeout command to call my application in timeout duration. And I also use 2>&1 | tee to write the log in my application to a log.txt file. The command: timeout 20 my_application ...
Trung Nguyen's user avatar
8 votes
2 answers
3k views

leave color in stdout but remove from tee

I want to see color output when in stdout to the console, but I want to remove it in a captured copy of the output from the tee command.  In my case, command_that_writes_color_to_stdout | tee file I'd ...
johnnyB's user avatar
  • 203
0 votes
3 answers
476 views

exporting global variable in tee process substitution subshells [closed]

command | tee >(var="$(command1)") >(var1="$(command2)") echo "$var $var1" Also tried moreutils pee command | pee 'var="$(command)"' 'var1="$(...
user avatar
1 vote
1 answer
573 views

get count of lines while in pipe

i have a bash script that looks like this: some_process | sort -u | other_process >> some_file I'd like to get the line count to while i'm streaming the data, after the data is sorted but ...
Binyamin's user avatar
  • 205
30 votes
2 answers
3k views

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 ...
ks1322's user avatar
  • 1,646
6 votes
1 answer
721 views

tee iso contents into dd or directly to /dev/sda?

Over a year back, I contributed to a tutorial on how to install NixOS on Linode. It seems like most tutorials that deal with putting iso files on installation media always use dd, which is why "...
Aaron Hall's user avatar
1 vote
0 answers
41 views

How to split a stream to two binaries with retry?

I have a binary that produces an audio stream in s16le format. I want to split this stream to two different processes, but I don't want the command to exit and interrupt process 1 if process 2 errors. ...
Nick Andre's user avatar
0 votes
1 answer
740 views

Get hash from file while you copy or move it

Say I copy a file with pv, is there any way to also get any hash, like md5, sha1, etc without having to read origin twice? It has to work with big files or block devices. Example command which does ...
Smeterlink's user avatar
0 votes
1 answer
580 views

How might I direct the output of "wget -qO- whatever.tar.gz" to both tar and sha256sum?

The following creates csfile with a hash in it, unpacks go1.17.4.linux-amd64.tar.gz downloaded from Golang's official website, prints out the checksum to stdout and then removes the no longer needed ...
John Smith's user avatar
0 votes
1 answer
52 views

Piping JShell REPL through tee

If possible, I would like to pipe JShell REPL through tee in the following manner: jshell | tee "~\jshell-`date +'%d_%m_%Y__%H-%M-%S'`.log" The command executes and Shell launches but no ...
Konrad's user avatar
  • 323
4 votes
1 answer
555 views

tee in for loop not working as expected

I'm trying to use tee in a for loop as such: for ea in $(ls *bam) do samtools mpileup -f $ref $ea | \ tee \ >(java -jar $varscan2 mpileup2indel --output-vcf 1 > vcf/"$(echo $ea | sed ...
Rebecca Eliscu's user avatar
2 votes
2 answers
961 views

Can we use $PIPESTATUS with the tee (or pee) command?

In my bash scripts, I often use pipes and would like to know which stage of the pipe was causing the problem in case of errors. The basic structure of such snippets is: #!/bin/bash ProduceCommand 2&...
Binarus's user avatar
  • 3,230
1 vote
3 answers
1k views

Is there a way to send all shell script output to both the terminal and a logfile, *plus* any text entered by the user?

I want to send output of a shell script, including user-entered text, to the terminal and a logfile. I thought some combination of tee and exec might do it, but I’ve had no luck so far. I know tee by ...
user494791's user avatar
0 votes
1 answer
358 views

BASH 4: tee to log file, fail over to /dev/null

I have a script that attempts to log its actions. There's a single tee in there that does all of this. Currently, when the $LOG_FILE cannot be written to the script dies. Instead, I would like it to ...
OstermanA's user avatar
  • 113
2 votes
1 answer
323 views

Can named pipes/FIFOs be used in a "cyclic" manner together with `tee`?

Why does the last line in this script gets stuck? #!/usr/bin/env bash trap 'rm -f numbers' EXIT mkfifo numbers decrement() { while read -r number; do echo "debug: $number" >&...
Ionuț G. Stan's user avatar
0 votes
0 answers
99 views

Userspace solution to use store data and create a UDP server

I'm trying to come up with a good way manage an intermittently connected device that I'm using for a research project. It's a sensor that goes in and out of the water. While under water, of course, ...
b degnan's user avatar
  • 111
4 votes
1 answer
75 views

What's wrong with this branched data flow using `tee`, fifos, and `paste`?

In the spirit of this question, I want to create a branched data flow from a single source: cmd1 ──> tee ──────────────> │    ├─────> cmd2 ─────> │ cmd4       └─────&...
Sasgorilla's user avatar
1 vote
0 answers
79 views

bash grep in a tee

I am trying to write a log file and output to a console at the same time The below works well. However I have a sleep timer and the logfile counts down each second and fills the log. The "...
waeking's user avatar
  • 11
5 votes
1 answer
1k views

How to redirect a command's `stdin` as well as `stdout` to the output

Suppose I have the Python script: #!/usr/bin/env python input('Y/n: ') print('Next line') After I press Y, I want both the terminal and my output.txt containing: Y/n: Y Next line Running the ...
simonzack's user avatar
  • 723
0 votes
1 answer
1k views

Having the output printed on the screen and redirected to a file and forwarded the errors to another file

I’m trying to answer this lab question. Is there a way to solve this without using tee command? As user1 on server1, run the ls command on /etc, /dvd, and /var. Have the output printed on the screen ...
Zar's user avatar
  • 11
2 votes
4 answers
2k views

Pipe result to multiple commands without writing on screen

I have a very big zip file (~10 GB) which I want to unzip, and the result has to be passed to two commands. The results of both subsequent commands have to be appended to a file, and Currently, I run ...
limitIntegral314's user avatar
4 votes
1 answer
825 views

why does tee refuse to work when launched remotely via ssh?

Where is my error? As an answer to a Stackexchange question, I tar a directory and transfer the archive to a remote system, where tee both deposits in a file and pipes it to tar for unpacking. My ...
berndbausch's user avatar
  • 3,517
0 votes
1 answer
156 views

Get the output of a remote ssh to local

I'm able to get the output of a failing lp command from a remotehost to my local script like below: until ssh -q root@remotehost 'lp -d Brother_HL_L2350DW_series /root/moht/Printed/`basename "$...
Ashar's user avatar
  • 469
4 votes
1 answer
2k views

How to uncompress a gzipped partition image and dd it directly to the destination partition without writing to current partition?

I've backed up a partition using sudo dd bs=8M if=/dev/sda2 | gzip > /someFolderOnSDB/sda2.img.gz. The image is stored on a separate disk sdb. When restoring it using gunzip -k /mnt/bkp/sda2.img.gz ...
Nav's user avatar
  • 359

1
2 3 4 5