我的桌面上有一个使用PowerShell创建的目录,现在我试图在其中创建一个文本文件。
我确实将目录更改为新目录,并键入了touch textfile.txt。
这是我得到的错误消息:
touch : The term 'touch' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ touch file.txt
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (touch:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException`为什么不起作用?我必须一直使用Git Bash吗?
发布于 2015-09-08 07:41:19
如果您需要在touch中使用PowerShell命令,您可以定义一个做正确事情的函数™:
function touch {
Param(
[Parameter(Mandatory=$true)]
[string]$Path
)
if (Test-Path -LiteralPath $Path) {
(Get-Item -Path $Path).LastWriteTime = Get-Date
} else {
New-Item -Type File -Path $Path
}
}将该函数放入您的配置文件中,以便在启动PowerShell时可用。
将touch定义为别名(New-Alias -Name touch -Value New-Item)在这里是行不通的,因为New-Item有一个强制参数-Type,并且不能在PowerShell别名定义中包含参数。
发布于 2015-12-06 01:10:54
如果使用Windows,则与Mac/Unix的触摸相同的命令是:New-Item textfile.txt -type file。
发布于 2019-09-27 06:44:44
用于power shell中的单个文件创建:ni textfile.txt
对于同时创建多个文件:touch a.txt,b.html,x.js是linux命令
ni a.txt,b.html,x.js是windows power命令。
https://stackoverflow.com/questions/32448174
复制相似问题