Linux: create a file with specific size








1. create an 1M bytes file:
dd if=/dev/zero of=output.dat  bs=1024  count=1024

2. You can also use K / M / G as extension for bs (block size).
dd if=/dev/zero of=output.dat bs=1M count=1

creates a 1M bytes file
3. The above examples create zero-filled file using /dev/zero, You can also use if=/dev/urandom to fill the file with random data instead of zeros. e.g.
dd if=/dev/urandom of=output.dat bs=1M count=1

4. See also this post.


No comments:

Post a Comment