Create a big file on RHEL/CentOS with zero's written on it (Testing Purpose)

Many times for the testing purpose you need to create big capacity dummy files on the filesystems to check few features of disks/arrays or some kind of drivers. So here I will show you how you can create such a big file and also depending on your requirement if you need just an empty file or you need to zero it out, means writing zero's on it.

To create an empty 50GB file using dd utility:

# dd if=/dev/zero of=/dummy-fill/dummy_file.img bs=1 count=0 seek=50G
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.00042393 s, 0.0 kB/s

Here above command will create 50GB of the file named "dummy_file.img" inside "/dummy-fill/" folder. Where "53687091200" is in Bytes which is equivalent to 50GB.


To create a big 50GB file and to write zero's on it follow below commands;

# dd if=/dev/zero of=/dummy-fill/dummy_file.img count=1024 bs=52428800
1024+0 records in
1024+0 records out
53687091200 bytes (50 GB) copied, 58.52256 s, 426 MB/s

"bs" stands for block size and the count is nothing but a number of such blocks used to create this big dummy file. so If you convert this to Bytes by multiplying "BS * count" will give you the total size of the file in bytes.

52428800 * 1024 = 53687091200 Bytes  = 50GB

]# ls -l /dummy-fill/
total 1048580
-rw-r--r-- 1 root root 53687091200 Feb 15 15:05 dummy_file.img

This last command will take some time depending upon the file size it has to zero out and the RAM/CPU present on your server or VM.

Comments

Popular posts from this blog

Recover or restore initramfs file in RHEL or CentOS 7

Space reclamation / UNMAP on RHEL or CentOS 7

How to recover /boot partition on RHEL or CentOS 7?