Creating a file with a specific size

The last week I had to test the transfer speed between two machines. I tested it sending files with different size. For creating those files I used the dd command which allows to create an empty file of desired size.

$ dd if=/dev/zero of=file_to_create bs=1k count=1024
1024+0 records in
1024+0 records out
1048576 bytes transferred in 0.010811 secs (96992910 bytes/sec)

/dev/zero is a special file that provides as many null characters (ASCII NUL, 0x00) as are read from it. In the above example, the bs option set both input and output block size to 1k, and the count option copy only 1024 input blocks, so that command will create a file (named file_to_create) with a size of 1MB.

Note that 1MB is 1024KB (count option) and not 1000KB as the hard drives vendors say ;)

1 Comment

  • On 06.27.09 hal0thane said:

    There’s also mkfile (at least on BSD-based systems), which is a bit less cryptic:

    mkfile 1m file_to_create

    If you just want to create a file, I’d use mkfile(8), but yes, if you’re specifically testing transfer speeds, dd(1) would be the way to do it.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields