Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Redirect output of a command to two different files

I know I can use tee, but I dont want the output to be printed on the screen I want them to be printed only on the file

example : ls > pk.txt 

Now, another file named praveen should also be created

share|improve this question

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
share|improve this answer
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).

share|improve this answer

If don't want to use tee, How about simple copy (cp) command?

ls > pk.txt ; cp -r pk.txt praveen    

OR use zsh, suggested by @Stephane, in bash shell, zsh can be used as:

zsh -c 'ls >pk.txt >praveen'
share|improve this answer

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