在windows机器上,我得到这个错误

“touch”不能被识别为内部或外部命令、可操作程序或批处理文件。

我遵循这些指令,似乎是linux特定的,但在标准的windows命令行上,它不是这样工作的:

touch index.html app.js style.css

windows中是否有类似于linux / mac os / unix世界中的'touch'命令?为了实现这类命令,我是否需要手工创建这些文件(并修改它们以更改时间戳)?我正在使用节点,这似乎不是很…node-ish……


当前回答

答案是错误的,它只在文件不存在时工作。如果文件存在,使用第一个不执行任何操作,第二个在文件末尾添加一行。

正确答案是:

copy /b filename.ext +,,

我在这里找到了:https://superuser.com/questions/10426/windows-equivalent-of-the-linux-command-touch/764721#764721

其他回答

是的,你可以使用Node for Touch,我只是使用它,它在windows Cmd或gitbash中工作都很好

对于一个非常简单的touch版本,它主要用于在当前目录中创建一个0字节的文件,另一种替代方法是创建一个touch.bat文件,并将其添加到%Path%或复制到C:\Windows\System32目录,如下所示:

touch.bat

@echo off
powershell New-Item %* -ItemType file

创建单个文件

C:\Users\YourName\Desktop>touch a.txt

    Directory: C:\Users\YourName\Desktop

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2020-10-14  10:28 PM              0 a.txt

创建多个文件

C:\Users\YourName\Desktop>touch "b.txt,c.txt"

    Directory: C:\Users\YourName\Desktop

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2020-10-14  10:52 PM              0 b.txt
-a----        2020-10-14  10:52 PM              0 c.txt

Also

工作与PowerShell和命令提示符。 使用现有子目录。 如果文件已经存在,则不创建该文件:

New-Item : The file 'C:\Users\YourName\Desktop\a.txt' already exists.

对于多个文件,只创建不存在的文件。 接受逗号分隔的不带空格的文件名列表,如果需要空格则用引号括起来:

C:\Users\YourName\Desktop>touch d.txt,e.txt,f.txt
C:\Users\YourName\Desktop>touch "g.txt, 'name with spaces.txt'"

在你的机器上安装NPM

在命令提示符中运行以下命令。

npm install touch-cli -g

现在你将能够使用触摸cmd。

我使用cmder(命令行模拟器)

它允许您在Windows计算机中运行所有Linux命令。

它可以从https://cmder.net/下载

我真的很喜欢

使用PowerShell, type: ni index.html或ni style.css或ni app.js

ni <filename>.<extension>