This question already has an answer here:

I know I can use tee, but I don't want the output to be printed on the screen; I want it to be printed only to the file.


ls > pk.txt 

Now, another file named praveen should also be created.

marked as duplicate by Stéphane Chazelas, Anthon, goldilocks, slm, Mat May 13 '14 at 12:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Use tee(1) to write to two files and discard stdout:

ls | tee pk.txt praveen >/dev/null

Edit2: As pointed out by Stephane and Thomas, because of how tee works, this is a better version and results in less writes:

ls | tee pk.txt > praveen
  • 3
    Why prune the tee output instead of doing ls | tee pk.txt > praveen? – Stéphane Chazelas May 13 '14 at 10:19
  • "...because of how tee works, this is equivalent to: ls | tee pk.txt > praveen" Actually, while the output might be equivalent, the former oneliner leads to unnecessary writes in order to discard the output, so the behavior is not equivalent. – Thomas Nyman May 13 '14 at 10:40

With zsh:

ls > file1 > file2

(internally, zsh creates a pipe and spawns a process that reads from that pipe and writes to the two files as tee does. ls stdout is the other end of the pipe).

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