Advertisements
Advertisements

I want to create a file using the command line in Windows. I have created files using the command line in Linux before and would like to know if I can do the same thing from Windows. Resolution:

The following tutorial demonstrates how to create a file from the command line when using a version of the Windows 11 operating system.

There are severals ways to create a file from the command line, and you may prefer using one method over the other depending on what you are putting in your files. Below I will explain the different methods, why you want to use them differently, and, finally, how to create the files from the command line.

Method One: How to Create File from Command Line Using Echo Command

You can create a file from the command line using the Echo command. Here is how to do that:

1. Open the Windows Terminal. See this tutorial for all the different ways in which you can open the Windows Terminal: How to Open Windows Terminal in Windows 11 [Tutorial].

2. From the top of the Terminal window, select the Command Prompt shell.

Windows Terminal app\Command Prompt

3. Type the following command into the command line and press the Enter key on your keyboard to execute it:

echo sample-text > filename.txt

Note: Change where it says “sample-text” with the actual text you would like to be in the text file.

Windows Terminal app\Command Prompt\echo command

4. You can now close the Terminal and continue using your computer.

Method Two: How to Create File from Command Line Using FSUTIL Command

The fsutil command is quite powerful and in most cases should only be used by Windows adminsitrators. Not coincidentally, it also requires adminsitrative privlidges over the command line to run, so this time you will need to open the elevated Windows Terminal window. Here is how to do that:

1. Open the elevated Windows Terminal. See this tutorial for all the different ways in which you can open the elevated Windows Terminal: How to Open Elevated Windows Terminal as Administrator in Windows 11 [Tutorial].

2. From the top of the Terminal window, select the Command Prompt shell.

3. Type the following command into the command line and press the Enter key on your keyboard to execute it:

fsutil file createnew filename number_of_bytes

Note: Change where it says “number_of_bytes” with the actual number of bytes you would like the text file to be, i.e., 5000.

Windows Terminal\Command Prompt\fsutil

4. You can now close the Terminal and continue using your computer.

In conclusion, that is how to create a file from the command line (CMD/Terminal) in Windows.

Advertisements
Advertisements