🛠️ How to split a Gzip file on Linux – IT is good

🛠️ How to split a Gzip file on Linux – IT is good

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

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

Breakdown the 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 kind of 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.

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.


#split #Gzip #file #Linux #good

Leave a Comment

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