Create text file using echo in command prompt
Asked Answered
S

3

8

I'm creating a hello_world.txt in the desktop using echo in command prompt and this is my input.

echo hello world > C:\Users\user\Desktop\hello_world.txt

The first code works, then I try %userprofile% if example, I want to give it to another user.

echo hello world > C:\Users\%userprofile%\Desktop\hello_world.txt

Doesn't work. Any simple echo command line to create text file?

Sacking answered 10/6, 2015 at 12:23 Comment(3)
What is your command line? Cygwin under Windows? cmd.exe?Rentroll
If you're used to linux shells, you can install git bash. You'll have fast all the linux command, and lines like echo hello world > C:\Users\user\Desktop\hello_world.txt will normaly work ;)Greenhorn
can you try to print the viariable %userprofile% by doing ech %userprofile% in your commande lineAluino
R
11

Your command should be:

echo hello world > %userprofile%\Desktop\hello_world.txt


It doesn't work if you put anything before %userprofile%, because it's a full path, so C:\Users\%userprofile%\Desktop\hello_world.txt gets substituted to C:\Users\C:\Users\cromix\Desktop\hello_world.txt.

Rentroll answered 10/6, 2015 at 12:31 Comment(0)
A
3

1. To create a new file and new text or To override everything that you have in your file with new text:

echo > file_name text_you_want_to_in_your_file

2. To add next text from new line:

echo >> file_name text_you_want_to_add_in_your_file
Ahriman answered 18/11, 2022 at 4:54 Comment(0)
V
-3

You can type:

touch <file name>

Very important NOTE: You can use this command only on cmder or Mac OS.

and this works in Windows by downloading cmder only.

This is an example

Verdure answered 25/6, 2017 at 21:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.