Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Windows 7 and I would like to quickly create a small text file with a few lines of text in the Command prompt.

I can create a single line text file with:

echo hello > myfile.txt

but how can I create a text file with multiple lines using this echo command? I have tried with the following, which doesn't work when I read the file with more:

echo hello\nsecond line > myfile.txt

Any suggestions? Or is there any other standard command that I can use for this instead of echo?

share|improve this question
    

2 Answers 2

up vote 7 down vote accepted

Could you use the >> characters to append a second line to the file, e.g.

echo hello > myfile.txt
echo second line >> myfile.txt
share|improve this answer

There are three ways.

Append each line using >>:

C:\Users\Elias>echo foo > a.txt
C:\Users\Elias>echo bar >> a.txt

Use parentheses to echo multiple lines:

C:\Users\Elias>(echo foo
More? echo bar) > a.txt

Type caret (^) and hit ENTER twice after each line to continue adding lines:

C:\Users\Elias>echo foo^
More?
More? bar > a.txt

All the above produce the same file:

C:\Users\Elias>type a.txt
foo
bar
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.