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.
Example:
ls > pk.txt
Now, another file named praveen should also be created.
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.
Example:
ls > pk.txt
Now, another file named praveen should also be created.
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
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).
tee
output instead of doingls | tee pk.txt > praveen
? – Stéphane Chazelas May 13 '14 at 10:19ls | 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