Linux‎ > ‎

How to create a certain size zipped file

Thank you for visiting this page, this page has been update in another link How to create a certain size zipped file
It's easy to create a file that is exact size you want.
For example:
dd bs=1024 count=1024 if=/dev/urandom of=1MiBtestfile
You will get it.

How do you get a exact 1MiB zipped file?
On windows, maybe easier, on linux, I haven't seen any tool can do it in one step yet.

Here is the way I do

create a bigger file first

$dd bs=1024 count=10240 if=/dev/urandom of=./testfile
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 1.08761 s, 9.6 MB/s

compress it

$bzip2 testfile

then split it

$split -b 1048576 testfile.bz2 1MiBtestfile
$ls -l 1MiBtestfile*
-rw-r--r-- 1 test test 1048576 Dec 19 11:44 1MiBtestfilexaa


If you have a huge big file, and you want to copy it to multiple tape volumes, here is the way.
tar -ML <unit in 1024bytes> cf <device> mybigfile

Save them to disk?
simple use split as I describe in article split and reassemble files on linux, or replace the tar tape device with disk file, but the extra manual copy action is needed before you enter for the next volume.