Powershell无法删除我刚刚写的文件

问题描述 投票:1回答:1

我想在AWS EC2 Windows Server上安装git。因此,我使用了Invoke-WebRequest下载便携式git exe

Invoke-WebRequest -Uri https://github.com/git-for-windows/git/releases/download/v2.23.0.windows.1/PortableGit-2.23.0-64-bit.7z.exe -UseBasicParsing -OutFile git.exe

但是下载卡住了,我终止了会话。现在,我想删除git.exe,但由于某些原因,我不允许这样做。我尝试使用以下方法删除文件:

Remove-Item .\git.exe

但是我收到一条错误消息,告诉我我不允许这样做

Remove-Item : Cannot remove item C:\git.exe: Access to the path 'C:\git.exe' is denied.
At line:1 char:1
+ Remove-Item .\git.exe
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\git.exe:FileInfo) [Remove-Item], UnauthorizedAccessException
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
amazon-web-services powershell amazon-ec2 windows-server
1个回答
0
投票
我刚刚发现Invoke-WebRequest没有正确终止,并且卡住的进程仍然使文件处于锁定状态。重新启动服务器后,我能够删除该文件。感谢您的建议和评论。
© www.soinside.com 2019 - 2024. All rights reserved.