split tar files into multiple files

How to Split Tar Into Multiple Files in Linux

Linux allows you to archive large files & folders into .tar files and move them easily. But sometimes, even your .tar files might be pretty big and you may need to split it into multiple files. In this article, we will learn how to split tar into multiple files in Linux. For this purpose, we will use split utility in Linux. It comes pre-installed in most Linux distributions so you don’t need to install it.

How to Split Tar Into Multiple Files in Linux

Here is the general syntax of tar command to archive files.

# tar options archive-name files 

Here is the general syntax of split command to split .tar file into multiple files.

# split options file "prefix”

In the above command, you need to specify the prefix to be used to name the .tar file’s parts, after splitting. based on the prefix, the parts will be named as prefixaa, prefixab, prefixac and so on. Let us say you have a tar file data.tar. Here is the command to split it into multiple files of 10Mb each.

# split -b 10M data.tar "data.tar.part"
# ls -lh data.tar.parta*
data.tar.partaa data.tar.partab data.tar.partac

You can use the split command to split any file, not just .tar files, into multiple files. Here are examples to split .tar.gz and .tar.bz2 files.

# split -b 10M data.tar.gz "data.tar.gz.part"
# ls -lh data.tar.gz.parta*
data.tar.gz.partaa data.tar.gz.partab data.tar.gz.partac

# split -b 10M data.tar.bz2 "data.tar.bz2.part"
# ls -lh data.tar.bz2.parta*
data.tar.bz2.partaa data.tar.bz2.partab data.tar.bz2.partac

Similarly, you can split an ISO image into multiple parts as shown below.

# split -b 10M data.iso "data.iso.part"
# ls -lh data.iso.parta*
data.iso.partaa data.iso.partab data.iso.partac

Yo can join these part files using cat command, to get back your original file. Here is a command to combine multiple part files created above.

# cat data.tar.parta* >data.tar
# cat data.tar.gz.parta* >data.tar.gz
# cat data.tar.bz2.parta* >data.tar.bz
# cat data.iso.parta* >data.iso

In this article, we have learnt how to split a tar file into multiple files, as well as how to combine the multiple part files into the original file. You can also use the commands as part of your shell scripts to automate file splitting tasks.

Also read:

How to Configure Samba Server in RHEL, CentOS
How to Rename All Files to Lowercase or Uppercase in Linux
How to Find Index of Item in Python List
How to Redirect Using JavaScript
How to Show All Users in MySQL

Leave a Reply

Your email address will not be published.