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

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. 

{ 8 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

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

Leave a Comment

Previous post:

Next post: