Create file from command line

We can create files from Command Prompt in Windows 11 and Windows 10 in two ways. The first way is to use fsutil command and the other way is to use echo command. If you want to write any specific data in the file then use echo command. If you are not bothered about the data in the file but just want to create a file of some specific size then you can use fsutil command.

To create file using echo

echo some-text > filename.txt

Example:

C:\>echo This is a sample text file > sample.txt
C:\>type sample.txt
This is a sample text file
C:\>

The > operator replaces the contents if the file already exists. To add another line without replacing the existing text, we can use >>:

Advertisement
echo This is another line >> sample.txt

The file is created in the current folder. To create it elsewhere, use a full path. Put the path in double quotes if it contains spaces, and make sure the folder already exists:

echo This is a sample text file > "C:\My Files\sample.txt"

To create file using fsutil

fsutil file createnew filename number_of_bytes

Example:

C:\data>fsutil file createnew sample2.txt 2000
File C:\data\sample2.txt is created
C:\data>dir
01/23/2016  09:34 PM     2,000 sample2.txt
C:\data>

The above example creates a file containing 2,000 bytes of zeroes. It does not create readable text like the echo example. See create a large dummy file for more file-size examples.

Limitations

If fsutil displays the below error, open Command Prompt as administrator and run the command again.

C:\>fsutil file /?
The FSUTIL utility requires that you have administrative privileges.
C:\>
Advertisement

14 thoughts on “Create file from command line”

  1. If you want to create a file with NO text in it do this:
    at the CLI type “Echo.”: Your output should look like this:
    C:\Temp>echo.

    C:\Temp>

    To write to a file:
    C:\Temp> Echo. >test.txt

    This will create a file with single space in the file.

    Reply
    • How can we use these commands to ‘touch’ a file. Could anyone provide the exact command that can work as linux ‘touch’ for any type of file?

Leave a Comment