tee: Direct output to standard output and File

Posted by Joys of Programming on in Linux

With linux pipes, you can direct the output of one program as an input to the other. But using pipes, you can only direct the output to another program. But if you wish to direct the output to the standard output as well as to a file, you can still use tee.

Take for example, if you want to list the contents of a directory on the terminal as well as save to a file.


ls dir | tee dir_contents

file1.txt file2.txt file3.txt


Tags: , ,

Comments:

1 Comment

  • Anonymous_ says:

    You could just forget about having to pipe the out put into yet another file and just use “>” to redirect output directly into a text file instead. you could just forget piping and just use “>” to redirect output directly into a text file instead.

    e.g.:
    ls dir > dir_contents

    Any pathrouting is valid too.

    e.g.:
    ls dir > path/to/textfile

    you could read from the pipe too

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.