How to concatenate multiple gz file as one file

This came out from a real need to combine lot of multiple gzipped files into a large file. It’s easier to manage a single file for processing in Big Data world, than processing lot of small simple files.

This tip covers on how to concatenate multiple files gzipped files as one. Here is the command

$time cat $(ls -t *.gz) > filename.gz

Here time command is just to get the time taken, and can be omitted.
-t is used to time sort the files, and can be ommitted if the need is not there
filename is the target file name

For Example, suppose we had hourly log files and we wanted to merge them into daily log file, here is the example

$time cat $(ls -t *.gz) > codezuzu-01-03-2015-daily-logs.gz

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.