Site icon WindowsLoop

How to Create A File Using Command Prompt or PowerShell

Need to create a file from command line? Follow these steps to create a file in Command Prompt or PowerShell in Windows.

In Windows, you can do a lot of things from the command line tools like the Command Prompt and PowerShell. Creating a new file from the command line is one such thing. In general, you easily create a new file directly in File Explorer. All you have to do is create a text file and rename it to whatever file type you want. For a vast majority of people, this is sufficient. However, there might be times when you need to create a new file from command-line tools like Command Prompt or PowerShell.

For example, if you are already running a specific script or command and need to create a file to edit, rather than creating it from the File Explorer, you can do it directly in the Command Prompt or PowerShell window. That way, you don’t have to leave the command line environment or go back and forth between windows. Not only that but when you create a file in Command Prompt or PowerShell, you don’t have to rename it to match a specific extension.

In this quick and simple guide, let me show you the steps to create a file in Command Prompt and PowerShell in Windows 10. The steps shown below will work in all versions of Windows including XP, Windows 7, Windows 8, and Windows 8.1.

Jump to:

Create a file in Command Prompt

The good old Command Prompt offers two different commands to create a new file in the command line. The first command is “echo” and the second command is “fsutil“. Both have their use cases.

For example, if you want to create a file with some content in it then use “echo”. This is very useful when you want to save the output of a command to a file. On the other hand, to create a blank file or a file with a specific size, use the “fsutil” command. I will show both, follow the one you like.

echo command

  1. Open the Command Prompt window.
  2. Use the cd command to go to the folder where you want to create the file.
  3. Use the below command to create a new file in Command Prompt.
    echo some content of your choice > filename.txt
echo command to create new file in command prompt

You can replace the dummy content with the content of your choice and the file extension can be anything.

In case you are wondering, you can also execute the echo > filename.txt command to create a file without manually inserting content. However, in that case, the echo command will automatically insert “ECHO is on” text in the file it created.

fsutil command

The fsutil is a very powerful command that can do a lot of things including creating new files from the command line. The advantage of fsutil is that it lets you create files from the command line without any content in them or files with a specific size. Follow the below steps to create a new file with the fsutil command.

1. Open the Command Prompt window.

2. Use the cd command to go to the folder where you want to create a new file.

3. Execute the below command to create a new blank file. The file can be of any extension.

fsutil file createnew filename.txt 0

fsutil command to create new file in command prompt

4. To create a new file with specific file size, use the below command. Replace “fileSize” with the actual file size in bytes.

fsutil file createnew filename.txt fileSize

For example, to create a 100 KB file, replace “fileSize” with “1000”. Then the command will look like this.

fsutil file createnew filename.txt 1000

Microsoft docs – fsutil command

Create a file in PowerShell

You can use the New-Item cmdlet to create a new file with the PowerShell command-line tool. Here’s how.

1. Open the PowerShell window.

2. Use the cd command to go to the directory where you want to create the new file.

3. Execute the below command to create a new file. Replace “filename.txt” with the file name and type of your choice.

New-item -Path . -Name "filename.txt" -ItemType "file"

PowerShell command to create new file

4. If you want to create a file with some content, use this modified command.

New-item -Path . -Name "filename.txt" -ItemType "file" -Value "Replace this content"

After creating the file, you can close the PowerShell window.

That is all. It is that simple to create a new file in Command Prompt and PowerShell. If you are stuck or need some help, comment below and I will try to help as much as possible.

If you like this article, check out how to hide a file with command line using the attrib command.

Exit mobile version