How to split a Gzip file on Linux

How to split a Gzip file on Linux
Share this:

How to split a Gzip file (database dump) into smaller files, transfer them to another server, and restore the database dump there?

How to split a Gzip file on Linux

In this guide, we will learn how to split a Gzip file on Linux.

Splitting a Gzip File

You can split a large file into smaller parts using the “split” command.


The syntax for the split command is as follows.

split [OPTION]... [INPUT [PREFIX]]

This command will output fixed size parts of the input file to PREFIXaa, PREFIXab, etc.

You can split the file according to the size of the required split files (option -b) or according to the number of lines (-l).

For example, you can split a file into 512MB files with the following command.

split –b 512m “file.gz” “file.gz.part-“

The system will create 512 MB files named file.gz.part-aa, files file.gz.part-ab, and so on.

Since you are trying to split the database dump, it is important that the files are not split across the same line.

To avoid this problem, you can split the file by the number of lines.

You can use zcat or “gunzip -c” to output lines from a zip file without decompressing the file itself, and then pipe the output to the split command like this.

zcat file.gz | split -l 2000000 - file.part


gunzip –c file.gz | split -l 2000000 - file.part


gzip -c file | split -b 1024m - file.gz.part

The system should create files with 2,000,000 lines each with names like file.partaa, file.partab, and so on.

You can then copy the split files to another server.

See also  How was the PlayStation 5 software cracked? Here is the answer!

Since this is a database dump file, there is no need to merge the files.

You can separately import split files into the database as follows.

mysql –u username –p dbname < file.partaa
mysql –u username –p dbname < file.partab

If you want to merge split files to create one file, you can do it like this,

cat file.part* > file.gz


In this quick tutorial, we learned how to split a Gzip file on Linux. Thanks for reading, please leave your feedback and suggestions in the comments section.

RelatedData Management platform: Best 15 major DMP platforms in 2022

Checkout: How to set Docker memory limit for containers

Share this:

Leave a Reply