title: How to redirect xz's normal stdout when do tar | xz?
body: <p>I need to use a compressor like xz to compress huge tar archives.</p>
  
  <p>I am fully aware of previous questions like
      <a href="https://stackoverflow.com/questions/18855850/create-a-tar-xz-in-one-command">Create a tar.xz in one command</a>
  and
      <a href="https://stackoverflow.com/questions/12313242/utilizing-multi-core-for-targzip-bzip-compression-decompression/27541309#27541309">Utilizing multi core for tar+gzip/bzip compression/decompression</a></p>
  
  <p>From them, I have found that this command line mostly works:</p>
  
  <pre><code>tar -cvf - paths_to_archive | xz -1 -T0 -v &gt; OUTPUT_FILE.tar.xz
  </code></pre>
  
  <p><strong>I use the pipe solution because I absolutely must be able to pass options to xz.</strong>  In particular, xz is very CPU intensive, so I must use -T0 to use all available cores.  This is why I am not using other possibilities, like tar's --use-compress-program, or -J options.</p>
  
  <p>Unfortunately, I really want to capture all of tar and xz's log output (i.e. non-archive output) into a log file.  In the example above, log outout is always generated by those <code>-v</code> options.</p>
  
  <p>With the command line above, that log output is now printed on my terminal.</p>
  
  <p>So, the problem is that when you use pipes to connect tar and xz as above, you cannot end the command line with something like</p>
  
  <pre><code>&gt;Log_File  2&gt;&amp;1
  </code></pre>
  
  <p>because of that earlier</p>
  
  <pre><code>&gt; OUTPUT_FILE.tar.xz
  </code></pre>
  
  <p>Is there a solution?</p>
  
  <p>I tried wrapping in a subshell like this</p>
  
  <pre><code>(tar -cvf - paths_to_archive | xz -1 -T0 -v &gt; OUTPUT_FILE.tar.xz) &gt;Log_File  2&gt;&amp;1
  </code></pre>
  
  <p>but that did not work.</p>