Creating file of 1MB, 2MB or {N}MB using shell command

Is it really possible to create a large file using shell?. I had the same question in my head and while looking at some of the shell commands man pages I figured that yes we can. So I thought this might be useful when doing some testing etc in a server like to check transfer bandwidth, file attach to a web page.

Ok here is the command to do that:

dd if=/dev/zero of=output.file bs=[BYTES] count=[BYTES]

Example 1 : create 1MB file:

dd if=/dev/zero of=output.file bs=1024 count=1024

Example 2 : create 2MB file:

dd if=/dev/zero of=output.file bs=2048 count=2048