首页 > 解决方案 > 为什么我可以在 Azure Cloud Shell Bash 中创建新文件和目录,但不能在 PowerShell 中创建?

问题描述

当我在 Azure Cloud Shell 中打开 Bash 时,我能够创建和编辑新文件和目录。

但是当我尝试在 Azure Cloud Shell 的 PowerShell 版本中执行此操作时,我无法执行任何这些操作。

例如,当我尝试创建一个新文件时:

Azure:/
PS Azure:\> new-item -Type file -Path my_new_files.txt
new-item : The node at path 'AzurePSDrive#Azure/my_new_files.txt' does not support the cmdlet 'New-Item'
At line:1 char:1
+ new-item -Type file -Path my_new_files.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotImplemented: (AzurePSDrive#Azure/my_new_files.txt:String) [New-Item], NodeDoesNotSupportCmdletException
+ FullyQualifiedErrorId : NewItem.NotSupported,Microsoft.PowerShell.Commands.NewItemCommand

当我尝试 cd 进入我已经从 Bash shell 创建的目录时:

Azure:/
PS Azure:\> ls
clouddrive  jjj  jjj.txt
Azure:/
PS Azure:\> cd jjj
cd : Cannot find path 'Azure:/jjj' because it does not exist.
At line:1 char:1
+ cd jjj
+ ~~~~~~
+ CategoryInfo          : ObjectNotFound: (Azure:/jjj:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

为什么我可以在 Bash 中 mkdir、touch、cd 和 vi,但似乎没有一个文件/目录命令在 PowerShell 中有效?

标签: azure

解决方案


这是一个已知问题。 Azure:具有到您的主目录的虚拟映射。主目录存储在一个名为 $HOME 的变量中。

大多数 PowerShell cmdlet 不能很好地与 Azure:\ 别名配合使用。要克服这一点,只需键入:

cd $HOME

进入主目录后,您的 cmdlet 将按照您编写的方式运行。


推荐阅读