4

Tip #787   Create a file of specific size

Recently I needed several files of certain sizes for testing the transfer speed between two machines. Files like this can easily be created with the dd command which lets you create an empty file of desired size.

$ dd if=/dev/zero of=dummy_file bs=1k count=2048
2048+0 records in
2048+0 records out
2097152 bytes (2.1 MB) copied, 0.0190557 s, 110 MB/s

$ ls -lh dummy_file
-rw-r--r-- 1 user group 2.0M 2009-05-11 10:05 dummy_file

/dev/zero is a special file that provides as many null characters (ASCII NUL, 0×00) as are read from it. In the above example, the bs option sets both input and output block size to 1k. The count option specifies 2048 input blocks, so that command will create a file (named dummy_file) with a size of 2MB (2048k).
 
  • TAGS:
  • dd