如何使用 Azure CLI 重命名 Data Lake Gen2 文件夹?

How to rename a Data Lake Gen2 folder using the Azure CLI?

我正在使用 Azure Data Lake Gen2,我有一个名为 myfolder 的文件夹,其中包含 1000s 个文件。 Azure 存储 CLI 上是否有用于重命名文件夹 and/or 将整个文件夹移动到 ADLS Gen2 的另一个位置 的命令?

在 Azure Databricks 中,我可以轻松利用 linux mv bash 命令:

是否有使用 Azure CLI 执行相同操作的简单方法?

根据我的研究,如果你想管理Data Lake Gen2目录,现在我们可以使用Azure data lake gen2 rest api. For more details, please refer to the document

例如,如果你想重命名你的文件夹,你可以使用the rest api

PuT https://<your account name>.dfs.core.windows.net/<file system name>/<new folder name>
Header:
x-ms-rename-source : /<file system name>/<orginal folder name>
Authorization : Bearer access token.

关于如何调用其余的api,请参考以下步骤 1. 创建服务主体

az login
az ad sp create-for-rbac --name ServicePrincipalName
  1. 为服务主体分配角色
az role assignment create \
    --role "Storage Blob Data Contributor" \
    --assignee < your service principal name> \
    --scope "/subscriptions/<subscription>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>"
  1. 调用其余的api
az login --service-principal  --username <your service principal app id> --password <your service principal password>--tenant <your tenant id>

az rest --method put --uri https://testadls05.dfs.core.windows.net/test/testFolder --resource https://storage.azure.com --headers x-ms-rename-source=/test/testFolder1

更新:ADLS Gen2 CLI 现在可用

我们可以使用 az storage fs directory move 命令重命名或移动目录。

示例 1:在同一文件系统中将目录从名称 my-directory 重命名为名称 my-new-directory

az storage fs directory move -n my-directory -f my-file-system --new-directory "my-file-system/my-new-directory" --account-name mystorageaccount --auth-mode login

示例 2:此示例将目录移动到名为 my-second-file-system.

的文件系统
az storage fs directory move -n my-directory -f my-file-system --new-directory "my-second-file-system/my

如需更多信息,请点击此处 official documentation