Sunday, February 10, 2008
7:09 AM

Create File of a Given Size

Last week, I needed to test the speed of my VPN connection. My plan was to create a file of some given size (say 10M), and test copy it to another server across the VPN tunnel.

My first task was to create a file of size 10M. On Solaris, it can be done simply by this command:
$ mkfile 10m output.dat 


On Linux, you can use the dd command:

$ dd if=/dev/zero of=output.dat  bs=1024  count=10240
10240+0 records in
10240+0 records out
10485760 bytes (10 MB) copied, 0.218581 seconds, 48.0 MB/s
$ ls -hl output.dat
-rw-r--r-- 1 peter peter 10M 2008-02-09 16:21 output.dat


The above dd command creates a zero-filled file named output.dat consisting of a count of 10240 blocks, each of block size 1024.

An anonymous commenter pointed out that you can also create a 10M file like this:
$ dd if=/dev/zero of=output.dat  bs=1M  count=10


Now that the 10m file has been created, I can time the copying of the 10m file like this:

$ time scp path/to/10m.dat  user@192.168.99.10:/some/location


If you can suggest other ways to create an arbitrary sized file, please share with us via comments.

P.S. Articles from this blog on the dd command:
Show progress during dd copy

StumbleUpon Toolbar

0 comments:

Post a Comment