You may need to cut down or split a file into smaller pieces sometimes. This is very useful when you want to cut down a large iso to fit into a DVD or CD. or can also be used to transfer over a network. To split the file into smaller pieces, we can use the split command.
The syntax for the split command is :
# split -b [size of split pieces] [file to split] [split file prefix]
For example to split an iso file image.iso of size 4.6GB into smaller chunks of 2000MB use the below command:
# split -b 1200M image.iso split-file
SIZE of the smaller files to be created may be one of the following, or an integer optionally followed by one of following multipliers:
|1000 x 1000
|1024 x 1024
This will generate 3 files with the following file sizes. You can specify the file prefix for the smaller files.
# du -sh chunks-a* 2.0G chunks-aa 2.0G chunks-ab 0.6G chunks-ac
To recreate the file, use the cat command.
# cat split-imga* > new-image.iso
The split and cat commands are provided by the coreutils package.
Verify the integrity of the file
Note: To verify that the file has been correctly restored, use the command md5sum before and after splitting the file. Syntax:
# md5sum [filename]
# md5sum image.iso 06caba513738f3af0ac475910e7f8a0f image.iso
After recreating the file from split pieces
# md5sum new-image.iso 06caba513738f3af0ac475910e7f8a0f new-image.iso