Tar archives can be split into multiple archives of a certain size, which is handy if you need to put a lot of content onto discs. It's also useful if you have a huge archive that you need to upload, but would rather do it in chunks. In this guide, we'll show you the commands you need in order to split tar archives into multiple blocks on a Linux system.

This will work regardless of what type of compression (or lack thereof) that you use. So files with extensions like .tar, tar.gz, tar.xz, etc. can all be split into chunks. We'll also show you how to extract files from archives that have been split into numerous files.

In this tutorial you will learn:
  • How to split tar archives into multiple files
  • How to open split tar archives
Splitting tar archive into blocks
Splitting tar archive into blocks
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software tar, split, and optional compression
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Split tar archives into multiple blocks

To split tar archives into multiple files, we'll pipe our tar command over to split. Let's look at an example.

This command will split a gzip compressed tar archive into 5MB chunks:

$ tar cvzf - example-dir/ | split --bytes=5MB - myfiles.tar.gz.
Tar command that will compress a directory into split files of a certain size
Tar command that will compress a directory into split files of a certain size

In our example, we split three large text files into 5MB tar archives. As you can see, the files end up with names like:

$ ls myfiles*
myfiles.tar.gz.aa  myfiles.tar.gz.ac  myfiles.tar.gz.ae  myfiles.tar.gz.ag
myfiles.tar.gz.ab  myfiles.tar.gz.ad  myfiles.tar.gz.af

SUBSCRIBE NEWSLETTER & RSS
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


You can use any options in your tar command that you'd like. For example, using bzip2 compression instead of gzip. What really matters is that you also include the - option, which sends tar output to stdout. The split utility can then interpret that data and split it into multiple files of a specific size.

If you need to split your archives into some other size, simply specify the proper size after the --bytes= option in the split command.

Open split tar archives

To open the split tar archive that we've created, you can use the cat command, piped to the tar command.

$ cat myfiles.tar.gz.* | tar xzvf -
Opening a tar archive that has been split into multiple files
Opening a tar archive that has been split into multiple files

The options you use with tar should be what you'd ordinarily use to extract the archive, along with the - option. In our case, we're extracting a tar archive that has been compressed with gzip, so we use xzvf.

Closing Thoughts

In this guide, we saw how to make tar archives on Linux, and have them split into multiple blocks of a certain size. The tar and split commands prove perfect for the job. It's a recurring theme on Linux for two or more commands to be strung together in order to achieve a single goal, and this is a perfect example of that.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.


Comments and Discussions