To create a file in Windows, right-click on your desktop or in File Explorer and click on New. Is this post going to be the shortest post ever? Nope. Because using the GUI sometimes won’t work, you can use the command prompt to create a file. In this tutorial, you will learn just about every way possible to use PowerShell and Windows command prompt to create file on the command line. Let’s get started!
PrerequisitesIf you’d like to follow along with the steps in this tutorial, be sure you have the following ahead of time:
Using Windows Command Prompt to Create FileYou have two command-line options in Windows; the command prompt (cmd.exe) or PowerShell. Let’s first cover how to use the Windows command prompt to create a file that is blank. To get started, open the Windows command prompt by clicking on the Start button, typing cmd.exe, and hitting Enter. The Windows command prompt should come up, and you’re ready to go. Using the ECHO CommandLet’s start this tutorial by first covering the echo command. The echo command is a command-line utility that allows you to display messages in a command prompt. In Windows, if you can send something to the command console, you can also redirect that output to a file! In the Windows Command Prompt window: 1. Run the echo command as shown below. This command echoes the text
provided ( When you’ve created the file, run the
You can see below that Windows creates the sample.txt file in the current working directory. 2. To confirm the file contains the expected “This is a sample text file” text, execute the You can see below that sample.txt does, indeed, contain the expected text. Using the COPY CON CommandIf the
To create a file using 1. Run 2. Once you see that flashing cursor type in some text you’d like to include in the file and press Enter.
When you’re done, press Ctrl-Z and press Enter to exit the interactive prompt. Pressing Ctrl-Z will also add an end-of-file marker to tell Windows to close the open file handle. You can see below pressing Ctrl-Z will display Using the FSUTIL CommandYou can also use Windows command prompt to create file by introducing fsutil! Fsutil is a file system management tool built into Windows. To use fsutil on the command prompt to create a new file: 1. Close the command prompt if you still have it open and open it up again, but this time as an administrator. Unfortunately, the fsutil utility requires it. 2. Now, invoke the The below command will create a file called sample.txt in the current working directory that’s 1KB in size.
3. Type
Creating a File with PowerShellIt’s now time to use a more modern approach of using a Windows command prompt to create file; with PowerShell! PowerShell has a few different ways to create a file so let’s cover them all. So, open your Windows PowerShell or PowerShell console and let’s get started! Using the New-Item CmdletOne of the easiest ways to create a file in Windows with PowerShell is to use the
1. Run the The below command will create a file called sample.txt in the current working directory (
2.
Now, take a look at the file just created using the Using the Set-Content and Add-Content CmdletsNext, let’s check out the With PowerShell still open, run the The command below will create a file called sample.txt in the current working directory with the text
Using the Out-File CmdletTo round out how to create a file on the command prompt with PowerShell, let’s end this tutorial with the The With PowerShell still open, type some text ( The below command will create a file called sample.txt in the current working directory with the text This is a test inside.
You can see below that PowerShell created a 16-byte file called sample.txt. ConclusionIn this tutorial you learned different ways to use PowerShell and Windows command prompt to create file. By now, you should know just about all the ways to create text files on the command line. Which method do you prefer? How do I add a file to Windows command line?Use these steps to create a plain text file that you can type into: Type copy con testfile. txt , but replace testfile with the desired file name. Press Enter.. Type type nul > filename. txt .. Replace filename. txt with whatever you want to call your new file. The ". ... . Press Enter.. What is insert mode in cmd?Insert Mode. Insert mode is the mode to be in when inserting text into the file. Command mode is the mode to be in when giving commands which will move the cursor, delete text, copy and paste, save the file etc. When entering a file, vi is in command mode. To enter text, you must enter insert mode.
What is command to add file?The git add command is used to add file contents to the Index (Staging Area). This command updates the current content of the working tree to the staging area.
How do I add a file in Terminal?How to create a file in Linux from terminal window?. Create an empty text file named foo.txt: $ touch foo.bar. ... . Make a text file on Linux: $ cat > filename.txt.. Add data and press CTRL + D to save the filename.txt when using cat on Linux.. Run shell command: $ echo 'This is a test' > data.txt.. |