Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to take the input from a serial port and write it to a file and also then read the file and send it back out the serial port to the host computer. A coworker suggested using the "tee" command but I can't find a good example/wrap my mind around the command. Is it possible to do this with "tee"? it seems that tee can only do one command, like cating a file to a different place, but not cating the port then writing to the document then reading the document and then sending it over the port. Or am i just not understanding the basics of the "tee" command.

share|improve this question
tee can take multiple output file arguments, which in this case would be the output file and the serial port. –  jw013 Jul 16 '12 at 20:41
Oh awesome. Thanks for the clarification! –  Julien Jul 16 '12 at 20:48
Related, but overkill here: How can I send stdout to multiple commands? –  Gilles Jul 19 '12 at 22:37

1 Answer 1

The tee command writes the input to standard output as well as to a file at the same time. A quick example would be

$ echo "Hi there..."|tee -a hi.txt
Hi there....
$cat hi.txt
Hi there....

In the above, example it presents the text in STDOUT and writes it to hi.txt. Another example could be

$cat hi.txt|tee -a final.txt
Hi there.....
$cat final.txt
Hi there....

So considering bash shell, your example could be-

$cat ./serial-port|tee -a <filename>

So if serial-port is 20002 then the above command would look like

$cat $serial-port|tee -a serial.txt
$cat serial.txt
share|improve this answer
And to pipe write it back to another serialport you would cat ./serial-port | tee -a localcopy.txt | ./outgoing-serial-port ... I think the OP wants to do that. –  Bananguin Jul 16 '12 at 21:55
Yeah that is pretty much exactly what I want to achieve. Thanks! –  Julien Jul 16 '12 at 22:01
When I run the command it says that ttyUSB0 directory doesn't exist. Did I do something wrong? cat ./ttyUSB0 | tee -a local.txt | ./ttyUSB0 –  Julien Jul 16 '12 at 22:08
i think you want to do something like cat ./ttyUSB0 | tee -a local.txt > ./ttyUSB0 –  Ann Jawn Jul 16 '12 at 23:33
Just to be clear... pipe sends the output of one command to another command in this case cat ./ttyUSB0 | tee -a local.txt | ./ttyUSB0 ./ttyUSB0 is not a command, rather maybe a file (or port). So in order to write the output back to the file (or port) u have to use > redirect operator –  Ann Jawn Jul 16 '12 at 23:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.