How to Create a Text File in Windows Command Line
Creating a text file through the Windows command line is a fast and convenient way to work with files. By using the echo
command or the notepad
text editor, you can easily create a file with the content you need. Let's go over several methods:
1. Create an Empty Text File Using the echo
Command
To create an empty text file, you can use the echo
command with output redirection. Open the command line (Win + R, then type cmd
) and enter the following command:
echo. > filename.txt
This command will create an empty file named filename.txt
in the current directory.
2. Create a File with Content Using the echo
Command
If you want to create a text file with specific content, use the echo
command followed by the text you want to write to the file:
echo Sample file content > filename.txt
This will create the filename.txt
file with the text "Sample file content". If the file already exists, its content will be overwritten.
3. Append Text to an Existing File Using the echo
Command
To append text to an existing file, use the command with double angle brackets:
echo Additional text >> filename.txt
This command will add the text "Additional text" to the end of the specified file without overwriting its current content.
4. Use the notepad
Text Editor
Another easy method is to create a file using the built-in Notepad text editor. In the command line, run the following command:
notepad filename.txt
If the file doesn't exist, Notepad will prompt you to create it. You can then immediately start typing the content and save the file using the editor's standard options.