Create a File of a Specific Size

Sometimes, you just have a need to have a file that is of a specific size.  For example, I want to test the real throughput of copying a file to my external drive over different connections (eSATA/FW800/USB2.0).

 

You can do this with the dd command.

 

Here is an example that will create a 100MB file file:

dd if=/dev/zero of=testfile bs=1024 count=102400

The bs operand tells you what byte size to use and the count operand tells you how many of bs you want.  So in the example, we are essentially asking dd to use a 1KB bs x's 102400.

 

You can also use k, m, g to instead of the full byte amount.  For example:

dd if=/dev/zero of=testfile bs=1m count=100

Now you can use the time command to see how fast you copy goes:

time cp testfile /Volumes/externaldrive/