You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Terminal中'touch'命令的等效替代命令是什么?

解决'touch'命令在Windows中不被识别的问题

问题原因

touch是类Unix系统(Linux、macOS)的原生命令,Windows的PowerShell或CMD默认没有这个命令,所以会抛出touch: The term "touch" is not recognized...的错误。

替代方案

1. PowerShell中直接创建空文件

  • 使用PowerShell自带命令创建空文件:
    New-Item example.js -ItemType File
    
    可简写为:
    ni example.js -Type File
    
  • 生成完全空的文件(和touch效果一致):
    echo $null > example.js
    

2. 在PowerShell中添加touch别名

如果习惯用touch命令,可在PowerShell中定义自定义函数:

function touch { New-Item -ItemType File -Path $args }

执行后就能直接用touch example.js创建空文件。

3. CMD环境中的替代命令

若使用CMD而非PowerShell,用以下命令创建空文件:

type nul > example.js

内容的提问来源于stack exchange,提问作者B.M. Garrett

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 01:02:38