In a Windows Command Prompt (CMD) and PowerShell when you execute the
echo
command to print some text or redirect it to a file, you can break it into multiple lines.
In Linux you can do this by using the
\n
.
This short note shows how to break lines and insert new lines using the
echo
command from the Command Prompt (CMD) and Windows PowerShell.
Cool Tip:
Windows
grep
command equivalent in CMD and PowerShell!
Read more →
Echo “Newline” in CMD & PowerShell
Windows Command Prompt (CMD)
To insert a line break in the Windows Command Prompt, you can use multiple
echo
commands as follows:
C:\> (echo Line & echo Newline) > file.txt
C:\> type file.txt
Newline
To print a new line in the Windows Command Prompt, use the
echo.
, for example:
C:\> (echo Line &
echo.
& echo Newline) > file.txt
C:\> type file.txt
Newline
Windows PowerShell
To insert a line break in the Windows PowerShell, you can use the
`n
character:
PS C:\> echo "Line
`n
Newline" > file.txt
PS C:\> type file.txt
Newline
The same
`n
character can be used to insert a new line in the Windows PowerShell:
PS C:\> echo "Line
`n`n
Newline" > file.txt
PS C:\> type file.txt
Newline