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
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 }
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…
What would be the command to create file of size 2 gb?
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.
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!
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.
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
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?
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
Hi
Great little article. I was just looking for a fast way to create a dummy file and FSUTIL can do that in seconds.
Can any one of you tell me, in which situations you need to create dummy files…?
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.
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.
Thanks, this helped me instantly create large files.
Thank you very much for this post!
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
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.
I have added explanation for the commands in the post.
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.
To create a 1MB file, run this
To create 32MB file run this
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.
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.