Videos
Factsheet
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.
Windows does not natively include a touch command.
You can use any of the available public versions or you can use your own version. Save this code as touch.cmd and place it somewhere in your path
@echo off
setlocal enableextensions disabledelayedexpansion
(for %%a in (%*) do if exist "%%~a" (
pushd "%%~dpa" && ( copy /b "%%~nxa"+,, & popd )
) else (
type nul > "%%~fa"
)) >nul 2>&1
It will iterate over it argument list, and for each element if it exists, update the file timestamp, else, create it.
in linux, touch command is typically used to create an empty file, not a directory! but in Windows Command Prompt(CMD) you can do like this to make a folder :
mkdir your_folder_name
or you can do it in Windows PowerShell like this
New-Item -ItemType Directory -Name your_folder_name
but if you want to create a new file with for example .txt extension, you can use the echo command like this in CMD:
echo. > my_empty_file.txt
or in PowerShell like this:
"" > my_empty_file.txt
good luck !
The touch command is typically used to create an empty file. As an alternative, on Windows, you can use something like this:
type nul > example.js
It will create an empty file called example.js in your current directory.
Before someone tells me to read the man or info pages, I do know what it does. That is not my question.
I'm asking in what specific situations do people use the touch command? A timestamp is usually something that does not need to be changed very often.
The Bash version included with macOS is quite old (3.2.57 as of Monterey 12.3.1) and doesn't honor leading zeros when expanding {01..10}, but newer versions of Bash do (from man bash):
A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer. When integers are supplied, the expression expands to each number between x and y, inclusive. Supplied integers may be prefixed with 0 to force each term to have the same width. When either x or y begins with a zero, the shell attempts to force all generated terms to contain the same number of digits, zero-padding where necessary.
I'd recommend that you install Homebrew and then Bash (5.1.16 as of this writing), and configure Terminal to use that version instead (correct the path below accordingly):

Without installing a package manager and then a newer version of your shell, you could work with the tools you have. Using the builtin command printf you could-
touch $(printf "file_%02d.txt " {1..10})
You could also use the external command jot-
touch $(jot -s " " -w 'file_%02d.txt' 10)
Now if you wanted to use the bash5 sequence expression {START..END[..INCREMENT]} then -
jot -s " " -w 'file_%02d.txt' 4 2 10
where 4 equal the number of times printed, 2 equals the increment, and 10 equal the maximum value.
Of course after all, you could use zsh within your "default" shell to do the lifting-
zsh -c 'touch file_{01..10}.txt'