Understanding tee
The tee
command is rather unique, because it’s not really a normal redirector. Rather, it’s a utility that can take output from a command and send it to both the screen and to a file at the same time. So, instead of using it with a redirector symbol as we’ve been doing, you’ll send it its input via a pipe.
If you need to see a command’s output on the screen and also save it as a text file, pipe the output of the command through the tee
utility, like this:
[donnie@fedora ~]$ ps a | tee ps.txt
PID TTY STAT TIME COMMAND
972 tty1 Ss+ 0:00 -bash
1005 pts/0 Ss 0:00 -bash
1076 pts/0 R+ 0:00 ps a
1077 pts/0 S+ 0:00 tee ps.txt
[donnie@fedora ~]$ ls -l ps.txt
-rw-r--r--. 1 donnie donnie 181 Aug 12 17:29 ps.txt
[donnie@fedora ~]$
Note that you don’t have to use the stdout
operator (>
) with this command. The name of the text file is used as the argument for tee
.