On a windows machine I get this error
\'touch\' is not recognized as an internal or external command, operable program or batch file.
No command – neither type
nor echo
– is necessary to emulate Unix's/Mac OS X's 'touch' command in a Windows Powershell terminal. Simply use the following shorthand:
$null > filename
This will create an empty file named 'filename' at your current location. Use any filename extension that you might need, e.g. '.txt'.
Source: https://superuser.com/questions/502374/equivalent-of-linux-touch-to-create-an-empty-file-with-powershell (see comments)
On windows Power Shell, you can use the following command:
New-Item <filename.extension>
or
New-Item <filename.extension> -type file
Note: New-Item can be replaced with its alias ni
You can also use copy con [filename] in a Windows command window (cmd.exe):
C:\copy con yourfile.txt [enter]
C:\CTRL + Z [enter] //hold CTRL key & press "Z" then press Enter key.
^Z
1 Files Copied.
This will create a file named yourfile.txt
in the local directory.
Assuming the file exists and you just need to update the timestamp.
type test.c > test.c.bkp && type test.c.bkp > test.c && del test.c.bkp
Yes you can use Node for Touch I just use that and its working all fine in windows Cmd or gitbash
in cmd window type:
type nul > your_file.txt
This will create 0 bytes in your_file.txt file.
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.
Edited on 2019-04-01:
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
Edited on 2020-04-07
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