bella.network Blog

Create a dummy file

The perfect way to fill up disk space without endless duplication of files
A lot of documents that are stacked on top of each other
A lot of documents that are stacked on top of each other (Image from Pixabay)

Ever wanted to create dummy files to test if your configured quota works as expected or to have a reason to buy a new disk?
Here is your way to go.

Windows

You can create a dummy file using fsutil where the created file is filled with zeros. If you have compression in place, this file will not consume a big amount of space.
To create the file, you can use the following command within cmd or PowerShell:

1
fsutil file createnew <filename> <size in bytes>

Linux

On linux based systems, we can use fallocate or dd for this task. fallocate is included in the package util-linux and is faster than dd.
dd, which is also known as disk dump or disk destroyer, is slower and comes with more risk but also with more options. The package should be preinstalled on your system already and comes mostly with the coreutils package.

Files created with fallocate is similar to fsutil of Windows which creates a file filled with zero. This file will compress pretty well but may not consume any disk space if the underlaying file system has compression enabled.

1
fallocate -l 1g <filename>

With dd we do have more possibilities when creating a new file. To create a file filled with zero, we can simply use the following command:

1
dd if=/dev/zero of=<filename> bs=<blocksize> count=<count of blocks>

The following parameters were used in the command above:

  • if - Input File: File from which to read from
  • of - Output File: File to which you want to write
  • bs - Block Size: Size of blocks you want to write. Ideally the same size as the block size of the underlaying disk.
    Disk sector size can be determined using fdisk -l | grep "Sector size" and block size can be determined using blockdev --getbsz /dev/<disk>
    For SSD and HDD it’s mostly 512 bytes or 4096 bytes.
  • count: Number of blocks. If your block size is 4096 and count is 1024, the created file will have a size of 4 MB.

Additionally, you have more possibilities to then to use if=/dev/zero as source for generating files.
For example you can use:

  • /dev/urandom: Will be very slow depending on the available entropy, CPU speed and disk write speed. This file will hardly compress efficiently.
  • /dev/<disk>: Will use an attached disk as source. This way you can clone an entire disk to a file. In this case you can omit the bs and count parameters.

Please note that if you want to make a backup and mix up if and of, dd will not hesitate to override all your data as fast as it can at the moment you execute the command.

Common sizes

Below some common sizes you can use for comparison when generating files:

SizeLength
10KB10240
1MB1048576
1.4MB (Floppy disk)1474560
25MB26214400
682MB (CD)715128832
1GB1073741824