Create an empty file on the commandline in windows (like the linux touch command)

An easy way to replace the touch command on a windows command line like cmd would be:

type nul > your_file.txt

This will create 0 bytes in the your_file.txt file.

This would also be a good solution to use in windows batch files.

Another way of doing it is by using the echo command:

echo.> your_file.txt

echo. – will create a file with one empty line in it.


If you need to preserve the content of the file use >> instead of >

>   Creates a new file
>>  Preserves content of the file

Example

type nul >> your_file.txt

You can also use call command.

Calls one batch program from another without stopping the parent batch program. The call command accepts labels as the target of the call.

Example:

call >> your_file.txt


or even if you don’t want make it hard you can Just install Windows Subsystem for Linux (WSL). Then, type.

wsl touch

or

wsl touch textfilenametoedit.txt

Quotes are not needed.

Leave a Comment