The files that are archived with the tar command can be split into multiple parts of a certain size. It is really helpful if you want to upload a large file to some drive or send it with a messaging application such as Telegram.
In this article, We’ll learn the commands through which you can easily split the tar archives into multiple files on a GNU/Linux-based system. This will work on any compression technique and hence, splitting of files with extensions like tar.gz, .tar and .tar.xz is possible.
Also read: Split and Compress Large Files using Zip in Linux [Quick Tutorial]
Split the archive
We will first split the archive by piping the output of the tar command with the split command, along with the specific size in which the individual blocks will be split. This can be achieved by the following command :
tar cvzf - XYZ/ | split --bytes=100m - myfiles.tar.gz
This command will compress the content of the directory named XYZ and then split it into parts of size 100 megabytes each. And you can use any option with the tar command as long as you include the ‘-’ option, it sends the tar output to stdout which is then interpreted by the split command.
Join the Split blocks and Uncompress
You can now send the individual blocks to another location and there, type the following commands to join the individual blocks and uncompress them simultaneously:
cat myfiles.tar.gz.* | tar xzvf -
This command will do the job easily, as the output of the cat command is piped to the tar command so that tar will recognize it as an input.
Summary
Piping the outputs of various commands is really helpful in the Linux Terminal. And with the help of just cat, tar, and split commands, we were able to save a lot of disk space and time while sending the files from one location to another.