Skip to main content
3 of 3
missing --s
Stéphane Chazelas
  • 585.1k
  • 96
  • 1.1k
  • 1.7k

The xz documentation says

It is possible to concatenate .xz files as is. xz will decompress such files as if they were a single .xz file.

From my tests, this works even if the different files are compressed with different options; so in your case

cat -- *.log.xz > newfile.log.xz

will work fine.

To answer your more general question, you can pipe the output of a compound command, e.g.

for file in -- *.log.xz; do xzcat -- "$file"; done | xz -ve9 > newfile.log.xz

or any subshell. This would allow you to perform any processing you want to on your log files before recompressing them. However in the basic case this isn’t necessary either; you can decompress and recompress all your files by running

xzcat -- *.log.xz | xz -ve9 > newfile.log.xz

If you add -f this even works with uncompressed files, so

xzcat -f -- uncompressed.log *.log.xz | xz -ve9 > newfile.log.xz

would allow you to combine uncompressed and compressed logs.

Stephen Kitt
  • 481.5k
  • 60
  • 1.2k
  • 1.4k