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 Fileni 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
相关产品推荐
相关产品推荐

