Tuesday, January 20, 2009

Create a file with given size - Linux dd command

Linux dd command (convert and copy a file) can be used for this purpose.


To create a 10 MB (10*1024*1024=10485760 bytes) size file named testfile_10MB

The command is:
$ dd if=/dev/zero of=testfile_10MB bs=10485760 count=1

1+0 records in
1+0 records out
10485760 bytes (10 MB) copied, 0.312 s, 33.6 MB/s

To confirm the size:

$ ls -lrth testfile_10MB
-rw-r--r-- 1 iam mygp 10M Jan 20 21:29 testfile_10MB


/dev/zero is a special file that provides as many null characters (ASCII NUL, 0x00) as are read from it.

if=FILE (read from FILE instead of stdin)
of=FILE (write to FILE instead of stdout)
bs=BYTES (force ibs=BYTES and obs=BYTES)
ibs=BYTES (read BYTES bytes at a time)
obs=BYTES (write BYTES bytes at a time)
count=1 (copy only 1 input block)

No comments:

© Jadu Saikia www.UNIXCL.com