Create a text file using echo on the command line

I am creating hello_world.txt on the desktop using echo on the command line and this is my input.

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

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

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

Does not work. Any simple echo command line to create a text file?

+3


source to share


2 answers


Your command should be:

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




It doesn't work if you put anything in front of it %userprofile%

, because it is a full path, so it C:\Users\%userprofile%\Desktop\hello_world.txt

is replaced with C:\Users\C:\Users\cromix\Desktop\hello_world.txt

.

+4


source


You can enter:

touch <file name>

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



and this works on windows by loading cmder only .

This is an example

0


source







All Articles