How to Compress and Split Directory into 100MB Chunks on Ubuntu
Managing large directories often requires compression and splitting for easier transfer or storage. This guide explains using tar and split commands on Ubuntu to compress a folder and divide the archive into manageable 100MB segments.
To begin, open your terminal and navigate to the parent directory
containing the folder you wish to compress. You will use the
tar command to create the archive and pipe it directly into
the split command to divide the file size. Run the
following command, replacing your_directory with the actual
folder name and archive_name with your preferred file
prefix:
tar czf - your_directory | split -b 100M - archive_name.tar.gz.This command creates a gzip-compressed tar archive and splits it into
100MB chunks named archive_name.tar.gz.aa,
archive_name.tar.gz.ab, and so on. You can now transfer
these smaller files individually.
To restore the original directory, ensure all split parts are in the
same folder. Use the cat command to reassemble the chunks
and pipe the output back into tar for extraction. Execute
the following command:
cat archive_name.tar.gz.* | tar xzf -This process concatenates the split files and extracts the contents immediately, restoring your directory to its original state.