How to create large dummy file

by admin on July 29, 2009

Fsutil.exe is a built in filesystem tool that is useful to do file system related operations from command line. We can create a file of required size using this tool.

syntax to create a file:

fsutil file createnew filename length
(length is in bytes)

For example, to create a dummy file test.txt, with size as 50MB :

fsutil file createnew test.txt 52428800

Note that the above command creates a sparse file which does not have any real data. If you want to create a file with real data then you can use the below command line script.

echo "This is just a sample line appended to create a big file.. " > dummy.txt
for /L %i in (1,1,14) do type dummy.txt >> dummy.txt

(Run the above two commands one after another or you can add them to a batch file.)

The above commands create a 1 MB file dummy.txt within few seconds.  If you want to create 1 GB file you need to change the second command as below.

echo "This is just a sample line appended to create a big file.. " > dummy.txt
for /L %i in (1,1,24) do type dummy.txt >> dummy.txt

Explanation:
The first command(echo…) creates the file dummy.txt with 64 bytes.
The second command, runs in a loop for 24 times, and each times doubles the size of the file, by appending it to itself.
One more example:

Create a 100MB file with real data:

echo "This is just a sample line appended  to create a big file. " > dummy.txt
for /L %i in (1,1,21) do type dummy.txt >> dummy.txt

The above command creates a 128 MB file.

{ 35 comments… read them below or add one }

Bruce May 17, 2011 at 7:45 am

That for loop is nice trick to create big files..
did not know creating 1 GB file would be that simpler without using any additional tool. Thanks for sharing. Cheers…

Reply

Anonymous May 17, 2011 at 4:39 pm

What would be the command to create file of size 2 gb?

Reply

Techblogger May 19, 2011 at 7:19 am

The command would be :

echo "This is just a sample line appended to create a big file " > dummy.txt

for /L %i in (1,1,25) do type dummy.txt >> dummy.txt

If you increase the bold number by 1, you can double the size of the file. If you decrease it by 1 you will reduce the file size by half.

Reply

blackq August 10, 2012 at 1:08 am

Could you please help with the following questions:

1. when I reduced the number of characters in the dummy.txt file, the size of the file got smaller after the “for /L … dummy.txt >> dummy.txt” loop. Would you please explain how this calculated?

2. “If you increase the bold number by 1, you can double the size of the file”. Would you please shed some light on this calculation?

Thank you very much!

Anonymous June 16, 2011 at 1:53 am

Is there a way to loop it to make a multiple large files? without manualy changing the txt file name, eg dummy1.txt dummy2.txt I'm trying to make a folder full of 4Mb files.

Reply

Techblogger June 16, 2011 at 5:34 am

You can do that. First create a file with the above commands and then create required number of files using copy command.

Create a 4MB file:
echo "This is just a sample line appended to create a big file " > dummy.txt

for /L %i in (1,1,16) do type dummy.txt >> dummy.txt

Now create more files using the above file. Let's say you want 20 files.


for /L %i in (1,1,20) do copy dummy.txt dummy%i.txt

Reply

Anonymous June 16, 2011 at 8:03 am

Awesome! that worked thanks a ton.
For anyone putting the command into a batch file you need to use double percentages to make it work, eg,

for /L %%i in (1,1,20) do copy dummy.txt dummy%%i.txt

I'm not sure why?

Reply

Techblogger June 16, 2011 at 12:48 pm

Yes, we need to use '%%' in batch files. Reason looks like batch files treat %1, %2 as command line parameters passed to the batch file. So one more % is needed to differentiate local variables.

source: http://support.microsoft.com/kb/75634

Reply

Thomas November 17, 2011 at 11:52 am

Hi
Great little article. I was just looking for a fast way to create a dummy file and FSUTIL can do that in seconds.

Reply

KWills March 14, 2012 at 1:03 pm

Can any one of you tell me, in which situations you need to create dummy files…?

Reply

admin March 15, 2012 at 5:04 am

If you are developing/testing/using a software program/script that is related to files/filesystems, you may need one. For example, if you are a system administrator and are deploying a new file replication software, you may want to evaluate the software if it works for all scenarios. For this, you can create files of varying sizes and test the software before the actual deployment.

Brett March 28, 2012 at 3:54 pm

This will create a highly compressible file since the same data is repeated over and over. That’s not necessarily a bad thing, but if you are testing file replication you may want to know if the compression is a factor or not in the replication performance.

Also if you want to do performance testing, caching could skew your results if its the same bits being loaded over and over.

Reply

Lokesh April 14, 2012 at 4:17 pm

Thanks, this helped me instantly create large files.

Reply

Anonymous June 12, 2012 at 7:17 am
echo "This is just a sample line appended to create a big file " > C:\dummy.txt
for /L %%i in (1,1,25) do type C:\dummy.txt >> C:\dummy.txt

Reply

blackq August 9, 2012 at 10:02 pm

Thank you very much for this post!

Reply

Abdul August 23, 2012 at 6:25 pm

After wasting a day on FSUTIL but I think this is what I need. But I dont’ know what thos numbers mean. Can some explain this please step by step:

echo “This is just a sample line appended to create a big file ” > dummy.txt

for /L %i in (1,1,25) do type dummy.txt >> dummy.txt

Reply

Abdul August 23, 2012 at 7:25 pm

I am not understanding those numbers. I would like to create files of 33MB, 34MB all the way to 50 increasing by 1 MB at a time. Can someone give me an example please. I could not follow the above example. I spent a day to create many files using FSUTIL but that’s not what I need since the data is not filled which is useless for real world testing.

Thanks.

admin August 24, 2012 at 6:24 pm

I have added explanation for the commands in the post.

Suneel Kuppili August 29, 2013 at 5:18 am

Its very Good Site, I have used this command to eat up 15GB space in my VM box just to test an installation of an application with less than 2 GB available space!

Excellent!

Reply

TTS September 17, 2013 at 11:51 am

Hi,
I have a requirement to create DOCX and PDF files with varying sizes (with valid data in it), can have random text but it needs to open successfully (i.e in Word & PDF). Any generatingg tools out there that can do the job quickly?

Reply

TTS September 17, 2013 at 11:53 am

I basically need to create around 120 PDF and 120 DOCX files (1MB, 5MB, 10MB etc) and looking at the best way to do it.

TTS September 17, 2013 at 11:59 am

Also all files need to be Unique (for my testing!!)

Any help would be much appreciated..

Ram September 27, 2013 at 10:08 am

Hi,
I have a requirement to create DOCX, PPT and PDF files with varying sizes (with valid data in it), can have random text but it needs to open successfully without displaying any error message ( i.e., Document has been corrupted or not in a valid format like that ..)
Can we’ve any command to do this. If any one suggest a tool well appreciated.
Thanks in Advance.
@TTS: Have you found any solution for this ?

Reply

Samir Gunic November 2, 2013 at 6:50 pm

I needed a 1 GB file. I followed your instructions and now I have a file that’s “0,99 GB (1 073 741 776 bytes)”. The “size on disk” however, is indeed “1,00 GB (1 073 741 824 bytes)”. Was this intentional? When doing things like upload test or download test, what matters is the actual size of the file, not how much space is allocated for the file on the disk. The operating systems and file system on the target machine might be completely different from the source machine. So what impact does this have? None, I’d say. You’re transferring the file (size of the file) and not entire blocks of disk drive (size on disk). So this needs to be corrected for. Other than that, very clever trick! Thanks!

Reply

Samir Gunic November 2, 2013 at 9:09 pm

The first command…

echo “This is just a sample line appended to create a big file ” > C:\dummy.txt

does not create a 64 byte file. The resulting file is only 62 byte! You can see that by counting the characters, but don’t forget to add 2 byte for CR and LF introduced by the command.

So try with following…

echo “This is just a sample line appended to create a big file…” > dummy.txt

The file should now be 64 byte. So when you use the second command you will now get exactly 1 MB for the first example. The size is “1,00 MB (1 048 576 bytes)” and size on disk is “1,00 MB (1 048 576 bytes)”. And for the second example, you should now get the file size “1,00 GB (1 073 741 824 bytes)” and size on disk “1,00 GB (1 073 741 824 bytes)” as well.

I did this on an NTFS volume with default 4096 byte clusters. Your mileage might vary.

Reply

admin November 6, 2013 at 8:26 am

Thanks for pointing that out, I corrected the command. Something went wrong looks like when I added the command in the post, I usually verify results are accurate.

Shan December 17, 2013 at 8:40 am

This is the best dummy file creator I have come across till now.

Reply

Jose March 11, 2014 at 7:34 pm

Thank you for hosting/posting this page. I did not know if windows could do this.

Reply

Stevan April 23, 2014 at 6:22 am

When running fsutil file createnew if u save the extension as %random% it will duplicate itself like crazy. For example one place to save this without needing admin rights is the public pictures folder. Here’s just a line of my code

:loop
Fsutil file createnew c:\users\public\pictures\hugefile.%random% 52428800
goto loop

This will create many of these files quickly. Fill a hard drive in seconds.

Reply

Johnny August 16, 2014 at 6:59 pm

Unfortunately the FSUTIL creates files with nothing in them (seems like FSUTIL just marks the drive space as used with a content length of zero), so it isn’t of much use when we want to test the compression options of a backup system.

Johnny August 16, 2014 at 6:56 pm

FYI. Thanks for the script. However, the script can only create files upto 4GB, even on an NTFS partition. Tried this on Windows 7, Windows Server 2008 and 2012R2. The problem seems to be the script. I am able to put 8GB ISO files in the same folder that I want to run this script. I have a feeling the “type” and pipe command doesn’t let you grow a file past 4GB.

Reply

admin August 10, 2012 at 5:16 pm

Answers:
1. The script initially writes the text specified in the command to the file. for(1,1,n) executes the type command n times. And each time the type command appends the file content in dummy.txt to the same file. So the size of the file doubles with each iteration. So if you decrease the number of characters in the initial file, automatically the size of the final file will also be lesser.
2. As explained above, if you execute the for loop n times, the size of the file at the end will be pow(2,n)*number of characters in the initial text.

Reply

admin August 24, 2012 at 6:27 pm

To create a 1MB file, run this

for /L %i in (1,1,14) do type dummy.txt >> dummy.txt

To create 32MB file run this

for /L %i in (1,1,19) do type dummy2.txt >> dummy2.txt

You can use dummy.txt(1MB size) & dummy2.txt(of size 32MB) to get the files of required sizes by appending 1MB file to 32MB, 33MB.. files.

Reply

blackq August 28, 2012 at 10:03 pm

Thank you for your explanation.

This method worked nicely when I created small files sizes such as 1MB, 1GB, 2GB. However, when I created 128GB file, the “for” loop time continued to run and even completed. However, the file size never grow greater than 4GB. I thought it might be a Windows 2003 limitation so I used another tool to create the 128GB file. That tool successfully created the big 128GB file. Maybe this append file method has a limitation at 4GB?

Thank you.

Reply

Boby August 14, 2014 at 9:26 am

Hi blackq ,

I think, that FAT32 took over from FAT16 and has a maximum drive size of 2TB. Its maximum file size is 4GB, so the file more than 4 GB will not be created.

Thank you!

Reply

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: