How to create a text file
Overview
CMD can create small text files without a full editor. Redirection sends command output to a file, while Notepad is better for longer or multi-line writing.
A single > creates or replaces a file. A double >> appends, so verify the filename before using either form.
- With
copy con, type lines, then press Ctrl+Z and Enter to save. type nul > filemakes a zero-byte file.echo.can append a blank line.
Commands to try
Type each command at the prompt, then press Enter. Replace sample names and paths with ones that exist on your computer.
Commands are generally not case-sensitive, but preserving the spelling shown here makes scripts easier to read.
echo First line> notes.txt
echo Second line>> notes.txt
type nul > empty.txt
notepad notes.txt
copy con typed.txt
Useful options and details
Options change how a command behaves. Add spaces exactly as shown, and use the command's built-in help when an option is unfamiliar.
A path containing spaces must be enclosed in double quotes, such as "C:\My Files".
>overwrites without a recycle-bin copy.>>preserves existing content and writes at the end.- Notepad may ask before creating a file that does not yet exist.
Tips and common mistakes
Check the current folder and read the command output before assuming an operation succeeded.
Practice with disposable files first. Commands that delete, overwrite, or stop a process may not offer an Undo button.
- Redirection writes plain text using the current console encoding, which may matter for non-English characters.
- Do not use
echoto store passwords or tokens; command history can expose them. - A space before
>becomes part of echoed text.
Safe practice
Create a temporary practice folder under your user profile so the examples cannot affect Windows system files.
After each command, inspect the result with dir or another read-only command before continuing.
- Create a two-line file in
CmdPractice. - View it with
type. - Create an empty file and confirm its zero size with
dir.