Questions tagged [tee]

tee is a command that reads from standard input and writes to standard output and to a file, so that the user can see output from a command at the same time as saving it.

The tee command allows the user to capture the output from a command to a file without preventing it from appearing in the terminal window, unlike > redirection. This provides, for example, a way of checking what is being written to a file, or of logging output for later examination.

enter image description here

Example:

$ echo "tee is a very useful command" | tee tee-love
tee is a very useful command
$ cat tee-love
tee is a very useful command

tee has a useful option -a to append to a file (by default, it overwrites an existing file with the new contents, or creates the file if it does not exist)

$ echo "<3" | tee -a tee-love
<3
$ cat tee-love
tee is a very useful command
<3
38 questions
224
votes
1 answer

How to append tee to a file in Bash?

These are commands I type in the terminal echo -e "First Line" | tee ~/output.log echo -e "Second Line" | tee ~/output.log When I look in the file output.log I only see 'Second Line'. How can I make sure that tee appends (rather than wipes out the…
Bluebeep
  • 2,401
73
votes
3 answers

Is there any significance to using tee?

Why is it that almost all instructions regarding appending text to system files like fstab and /etc/apt/sources.list.d/.list involve using tee and echo to append said text? Take the following examples, which are run as root: ## 1 echo 'deb…
Alexej Magura
  • 1,396
  • 1
  • 10
  • 14
19
votes
2 answers

Tee doesn't get whole output from the pipe

I have a script executing commands like: export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH;./some_app -i $INDEX | tee $LOG echo "Number of errors: $(grep "ERROR" $LOG | wc -l)" The problem is probably in the pipe to tee. It does not seem to get the whole…
17
votes
4 answers

Reading and writing a file: tee command

It is well known that a command like this: cat filename | some_sed_command >filename erases file filename, as the output redirection, being executed before the command, causes filename to be truncated. One could solve the issue in the following…
10
votes
6 answers

Debugging preseed/late_command for ubuntu 16.04 server: tee not found vs nonexistent directory

I am trying to run the following preseed file on a ubuntu 16.04 server machine (during a packer build): d-i preseed/late_command string \ in-target mkdir -v -p -m 0440 "/etc/sudoers.d"; \ in-target echo "%vagrant ALL=(ALL) NOPASSWD: ALL" | tee -a…
10
votes
2 answers

lint: command not found

Does Ubuntu have a lint utility? How is it installed? In computer programming, lint is a Unix utility.. https://en.wikipedia.org/wiki/Lint_%28software%29 thufir@mordor:~$ thufir@mordor:~$ gcc program.c -o prog program.c:5:1: warning: return type…
Thufir
  • 4,631
7
votes
2 answers

Is there a way to use tee with the whole script from INSIDE the script?

I'm making a script to update the system (Ubuntu 22.04), updating all packages in apt, flatpak and snap with one order (like sudo ./update.sh) and, in case something goes wrong, I want to save the output in a file. I have two ways to do this. One is…
5
votes
1 answer

sudo with tee displays staircase

Previously I ran without sudo and used tee to display on terminal and log to file: ./my_app | tee path/to/log_file Now I need sudo: sudo ./my_app | tee path/to/log_file However, because of tee when I add sudo my output has weird diagonal…
3
votes
1 answer

Why is the tee command necessary?

On Ubuntu my Brightness keys don't work. So instead to open Ubuntu settings every time, I want to write a shell script to use in my .bashrc. Now I don't understand at all why the tee command in the following line seems to be neessary! Thanks! sudo…
v217
  • 368
3
votes
2 answers

'sudo tee' command gone wrong | Removing a source.list that can't be read?

This has happened twice where I followed instructions on installing software and then having the software center open then close immediately as a result of running the commands from the instructions. The first incident happened when I was trying to…
3
votes
2 answers

tee results in a null file

I try to change Apache configuration with this: sudo awk '//,/AllowOverride None/{sub("None", "All",$0)}{print}' /etc/apache2/apache2.conf | sudo tee /etc/apache2/apache2.conf > /dev/null After this /etc/apache2/apache2.conf…
MikkoP
  • 185
3
votes
1 answer

how to redirect output to a log file without tee? normal redirection is not working

why not use tee? because the terminal rendering of the output makes the application run slower. for some reason, this is not working: application 2>&1 >"$logFile" the output keeps going to terminal..
3
votes
2 answers

How to append date and text to a file as an alias?

I want to create an alias to append a dated note to a file. (The use case I want to reproduce : Sebastian Daschner - How to do effective note taking as developer. So far I was able to append the date, but I cannot figure out a way to append both the…
2
votes
1 answer

Grep output from application, show to screen and write to file?

I run an application and pipe the output to grep. This works. However, I wish to show the output on both screen and write to file. So I am piping the grep result to tee: ./app | grep something | tee file.txt However, this is not showing (or…
2
votes
1 answer

tee: constraint_0_power_limit_uw: No data available

I am trying to replace value in the file of constraint_0_power_limit with new value using echo "45000000" | sudo tee constraint_0_power_limit_uw That file is under /sys/class/powercap/intel-rapl/intel-rapl:0/ When I use above command, I get tee:…
Mehmet
  • 107
  • 1
  • 1
  • 7
1
2 3