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.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI 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
tee
output instead of doing ls | tee pk.txt > praveen
?
May 13, 2014 at 10:19
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).