在 Windows 计算机上我收到此错误
'touch' is not recognized as an internal or external command, operable program or batch file.
我正在关注这些instructions这似乎是 Linux 特定的,但在标准 Windows 命令行上它不会像这样工作:
touch index.html app.js style.css
Windows 中是否有与 linux/mac os/unix 世界中的“touch”命令等效的命令?我是否需要手动创建这些文件(并修改它们以更改时间戳)才能实现此类命令?我正在使用节点,这看起来不太......节点式......
最佳答案
在 Windows 命令行(如 cmd)上替换 touch 命令的简单方法是:
type nul > your_file.txt
这将在 your_file.txt
文件中创建 0 个字节。
这也是在 Windows 批处理文件中使用的一个很好的解决方案。
另一种方法是使用 echo命令:
echo.> your_file.txt
回声。 - 将创建一个文件,其中包含一个空行。
<小时/>如果您需要保留文件的内容,请使用 >>
而不是 >
> Creates a new file
>> Preserves content of the file
示例
type nul >> your_file.txt
<小时/>
您还可以使用call命令。
Calls one batch program from another without stopping the parent batch program. The call command accepts labels as the target of the call.
示例:
call >> your_file.txt
--- 或者即使您不想让它变得困难,您也可以只需安装 Windows Subsystem for Linux (WSL)。然后,键入。
wsl touch
或
wsl touch textfilenametoedit.txt
不需要引号。
关于windows - 在windows中的命令行上创建一个空文件(如linux touch命令),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011267/