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.


2 Answers 2


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? May 13, 2014 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. May 13, 2014 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.