Create file with random data and specific size

Here is a quick bash one liner to to create a file with random data and a specific file size

This command will create a 2 MB file with random contents:


$ dd if=/dev/urandom of=test.zip bs=1M count=2
2+0 records in
2+0 records out
2097152 bytes (2.1 MB) copied, 0.208422 s, 10.1 MB/s

To view the file contents use:

hexdump test.zip |less

0000000 e209 6901 5e31 3747 7c24 4643 4c5f 74e7
0000010 8b99 fabb 74fa d3ed a5f1 90d9 e751 9ead
0000020 baea bec2 b0ca 5f2b 8719 8091 bb0e f82f
0000030 bf54 1c37 d764 a3bb 00c5 1871 ab6f 2c2b
0000040 b4d1 8e8e 1eeb ee19 8c58 31e0 58da 58d5
0000050 94d0 2141 c87e 5184 a722 594c 779a aa0a
0000060 01e4 ecaf a43c b5d8 1977 07cd de20 306f
0000070 13d3 1ef1 5d7d a482 e39b 086e 00f1 defd
0000080 8ec8 ed3d 2cb2 8f60 0da5 21e1 63df 21b0
0000090 a4b4 4617 c400 d9a5 694a 83bb 54d7 3874
00000a0 8b17 bc0c 9418 b287 a8e7 0475 be9c 9412
00000b0 548a a917 a577 b0f5 2806 9c8e 1728 5b9a
00000c0 a737 0fb7 070e dde9 b0fb a616 8133 0544
...

If running the command as root, you may want to chmod the file to 777 for access if using it as a test file to upload.

Enjoy.

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....