how to redirect a output of a command to two files

前端 未结 6 1622
孤独总比滥情好
孤独总比滥情好 2020-12-06 09:47

i need to redirect a output of a command to two files say file1 and file2 file1 is a new file and file2 is already existing file where i need to append the output i have tri

相关标签:
6条回答
  • 2020-12-06 10:09

    For Windows (cmd.exe):

    command > file1 & type file1 >> file2
    
    0 讨论(0)
  • 2020-12-06 10:09

    Assuming you're on a Linux-like system, try

    command | tee file1 >> file2
    

    tee splits the output stream and sends it to two destinations.

    0 讨论(0)
  • 2020-12-06 10:13

    In Linux, you can do this

    command | tee file1 >> file2

    0 讨论(0)
  • 2020-12-06 10:15

    You are looking for the tee command.

    $ echo existing >file2
    $ date | tee file1 >> file2
    $ cat file2
    existing
    Mon Mar  9 10:40:01 CET 2009
    $ cat file1
    Mon Mar  9 10:40:01 CET 2009
    $
    
    0 讨论(0)
  • 2020-12-06 10:16

    It will be possible using the following command. command | tee -a file1 file2

    0 讨论(0)
  • 2020-12-06 10:24

    In PowerShell use tee-object (or its tee alias)

    command | tee first-file | out-file second-file
    

    Can also tee to a variable (e.g. for further processing).

    0 讨论(0)
提交回复
热议问题