The echo command in Windows prints text to the screen or writes it to a file. Open Command Prompt (press Windows key, type cmd, press Enter), type echo Hello, and press Enter — Windows prints Hello on the next line. That is the whole command for the simplest use. The rest of this guide covers the switches that make echo useful in scripts, plus the mistakes that trip people up.
What You'll Need
- A Windows PC (Windows 10 or 11; the command works the same on older versions).
- Command Prompt or PowerShell — both accept
echo. - No administrator rights needed for basic use. Writing to protected folders such as
C:\Windowsdoes require an elevated prompt. - Optional: a text editor such as Notepad if you plan to write batch files.
Step-by-Step
- Open a terminal. Press the Windows key, type
cmd, and choose Command Prompt. Alternatively press Win+R, typecmd, and press Enter. For PowerShell, typepowershellinstead. Menu labels can differ slightly by Windows version and region. - Print a line of text. Type
echo Hello worldand press Enter. The words appear below your command. Quotation marks are not required unless the text contains special characters such as&,|,<,>, or^; wrap those in double quotes, for exampleecho "Tom & Jerry". - Print a blank line. Type
echo.(with the period, no space) and press Enter. A bareechoprints whether echo is on or off instead of a blank line, which is a common surprise. - Write text to a file. Type
echo Hello > notes.txtand press Enter. This createsnotes.txtin the current folder, replacing it if it already exists. Check your current folder withcdfirst, or give a full path such asecho Hello > C:\Users\YourName\Desktop\notes.txt. - Append instead of overwrite. Use double greater-than:
echo Second line >> notes.txt. Each run adds a new line at the end. - Turn command echoing on or off inside a batch file. In a
.batfile,@echo offas the first line stops Windows from printing each command as it runs;echo onrestores it. This only affects batch files, not what you type interactively. - Use it in a script for feedback. A line such as
echo Copying files...between commands gives the person running the script a status message. Combine withpauseif you want the window to stay open.
Common Mistakes
- Using a single
>when you meant to append. One arrow overwrites the whole file. There is no undo; the previous contents are gone. - Forgetting to quote special characters. An unquoted
&or|makes the shell treat the rest of the line as a new command, producing confusing errors. - Expecting
echoalone to print a blank line. It reports the echo state instead. Useecho.for a blank line. - Writing to the wrong folder. The file lands in whatever directory the prompt is showing. Run
cdto confirm before writing. - Assuming
@echo offworks at the prompt. It is a batch-file directive. Typed interactively it does nothing useful. - Confusing Command Prompt and PowerShell behaviour. Both have
echo, but PowerShell's version is an alias forWrite-Output, so some redirection and quoting rules differ. If a command behaves oddly, check which shell you are in.
Tips
- Use
echo %DATE% %TIME%to stamp a log line with the current date and time. - Print an environment variable with
echo %USERNAME%orecho %PATH%. - To include a literal percent sign, type it twice:
echo 100%%in a batch file. - Keep batch files in a folder you control and give them clear names; running them from the Desktop is fine but clutters it.
- Test redirection with a throwaway filename before pointing it at anything important.
Troubleshooting
"Access is denied" when writing a file. The target folder is protected. Write to your Documents or Desktop folder instead, or open Command Prompt as administrator if you genuinely need that location.
The text appears but the file is empty. Check for a stray space after > combined with a quoted string, and confirm you are looking in the folder shown by cd. Also check the file extension — Notepad may hide .txt.
Special characters break the command. Put the whole string in double quotes. If you need a literal quote inside, escape it according to the shell you are using.
Nothing prints in a batch file. The script may have @echo off and no explicit echo lines, or it may be exiting before reaching them. Add a pause at the end to see output.
PowerShell shows different output. PowerShell treats echo as an alias and formats output differently. Use cmd if you need classic behaviour, or switch to Write-Output in PowerShell scripts.
If that did not work, close and reopen the terminal, confirm you are in the expected folder with cd, and try the simplest form echo test before adding redirection.
Frequently Asked Questions
Does echo work in PowerShell?
Yes. In PowerShell, echo is an alias for Write-Output. Basic printing works the same, but quoting and redirection follow PowerShell rules rather than Command Prompt rules.
How do I print a blank line?
Type echo. with the period and no space. A plain echo reports whether echoing is on or off.
What is the difference between > and >>?
Single > creates or overwrites the file. Double >> appends to the end of an existing file.
Can echo create a folder?
No. Echo writes text to a file or screen. Use mkdir to create a folder, then echo a file into it.
Why does my batch file print every command?
Command echoing is on by default. Put @echo off as the first line of the batch file to suppress it.
Is echo dangerous?
Not by itself, but redirection can overwrite files without warning. Avoid pointing > at files you did not create or do not have a backup of.