Linux how to create a 1 MB file

The dd command copies a input file to an output file. It takes the number of loops and the block size in input.

Run the following command:


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

Example:

This example creates a file from /dev/zero and copies 1024 times 1024 blocks. This way the output file is 1MB. The ls -alh shows the output file size.


$  dd if=/dev/zero of=output.txt count=1024 bs=10241024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.00607721 s, 173 MB/s
$ ls -alh
total 1.1M
drwxrwxrwt  2 root root 4.0K May  3 14:50 .
drwxr-xr-x 22 root root 4.0K Nov 24 23:48 ..
-rw-r--r--  1 root root 1.0M May  3 14:50 output.txt
/tmp$

References:

dd unix

Share this article:

Recent Comments