Tuesday, 15 January 2013

How to Create a File of a Particular Size in UNIX or Linux

I needed a file with a size of 512 bytes for an Oracle test. I created it as follows:

UBUNTU > dd if=/dev/zero of=test1 bs=1 count=512
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.0140867 s, 36.3 kB/s
UBUNTU > ls -l test1
-rw-rw-r-- 1 andrew andrew 512 Aug 11 22:34 test1
UBUNTU >

To create a file with a size of 1000 bytes, you only have to change count=512 to count=1000:

UBUNTU > dd if=/dev/zero of=test2 bs=1 count=1000
1000+0 records in
1000+0 records out
1000 bytes (1.0 kB) copied, 0.0174102 s, 57.4 kB/s
UBUNTU > ls -l test2
-rw-rw-r-- 1 andrew andrew 1000 Aug 11 22:35 test2
UBUNTU >