Archives are a common way of storing and transferring multiple files in Linux. However, extensive archives can be difficult to manage and transfer, especially if they exceed a certain size limit. One solution to this problem is to split the large archives into multiple smaller files, each with a specified size limit. In this article, we will explain how to split large archives in Linux using the command line.
To split an archive in Linux, we will use the `split`
command. The split command is a standard Linux command that can be used to split files into smaller parts. When used with large archive files, the split command can break down a large archive into smaller files, each with a specified size limit.
Here’s how to split a large archive using the split command:
Step 1: Create an archive
Before we can split the archive, we need to create it. To create an archive use the following syntax:
tar -cvf archive.tar dir1 file1 file2
zip -r archive.zip dir1 file1 file2
Replace `archive.tar` or `archive.zip` with the name of your archive, and replace file1, file2, and dir1 with the names of the files you want to include in the archive.
Step 2: Split the large archive
Once you have created the archive, use the following syntax to split it into smaller files:
1 | split -b [size-limit] archive [prefix] |
Replace `[size-limit]`
with the size limit for each split file, in bytes. For example, if you want to split the archive into files with a size limit of 100 MB, use -b 100000000. Replace `[prefix]`
with the prefix for the split files.
split -b 100M archive.tar.gz prefix_
Step 3: Verify the split files
To verify that the split has worked, you can use the ls command to list the split files:
ls -l prefix_*
You should see a list of files with names like prefix_aa, prefix, etc.
It’s important to note that when you split an archive, the split files are not complete archive files, but rather parts of the original archive. To extract the files from the split archive, you will need to extract each split file individually or combine the split files into a single archive.
Conclusion
In conclusion, splitting archives in Linux using the command line is a simple process that can help you manage and transfer large amounts of data more easily. By using the split command, you can break down large archives into smaller files with a specified size limit, making it easier to handle and transfer your data. Whether you’re backing up data or transferring large amounts of data between systems, the split command is a valuable tool to have in your Linux toolkit.