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.

{ 21 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.

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

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: