英文:
Azure CLI - Delete files in storage account with pattern
问题
I need to delete all files and directories except the mf folder and its content.
I use this command:
az storage blob delete-batch --source 'CONTAINER' --account-name STORAGE_ACCOUNT --pattern '[!mf]*';
The problem that this command not only avoids deleting the mf directory but also the files that start with the letter m and f.
Is there a way to modify the pattern to include files starting with m and f?
英文:
I have the following files and directories in my container.
I need to delete all files and directories except the mf folder and its content.
I use this command:
az storage blob delete-batch --source 'CONTAINER' --account-name STORAGE_ACCOUNT --pattern '[!mf]*'
The problem that this command not only avoids deleting the mf directory but also the files that start with the letter m and f
Is there a way to modify the pattern to include files starting with m and f?
答案1
得分: 0
我需要删除所有文件和文件夹,除了mf文件夹及其内容。
您可以使用PowerShell作为另一种方法来删除除mf文件夹及其内容之外的所有文件和文件夹。
命令:
$ctx = New-AzStorageContext -StorageAccountName 'venkat123' -StorageAccountKey 'your-storage-account-key'
$containerName = "test"
$prefix = ""
$blobs = Get-AzStorageBlob -Container $containerName -Context $ctx -Prefix $prefix
foreach ($blob in $blobs) {
if ($blob.Name -notlike "mf/*") {
Remove-AzStorageBlob -Blob $blob.Name -Container $containerName -Context $ctx
}
}
最初,我有一些文件的结构。
当我使用上述命令时,它会删除所有文件和文件夹,除了mf文件夹。
输出:
门户:
英文:
> I need to delete all files and directories except the mf folder and its content.
You can use the Powershell as an alternative way to achieve delete all files and directories except the mf folder and its content.
Command:
$ctx = New-AzStorageContext -StorageAccountName 'venkat123' -StorageAccountKey 'your-storage-account-key'
$containerName = "test"
$prefix = ""
$blobs = Get-AzStorageBlob -Container $containerName -Context $ctx -Prefix $prefix
foreach ($blob in $blobs) {
if ($blob.Name -notlike "mf/*") {
Remove-AzStorageBlob -Blob $blob.Name -Container $containerName -Context $ctx
}
}
Initially, I had a structure of files.
When I use the above command it deletes all files and folders except the mf folder.
Output:
Portal:
答案2
得分: 0
为了继续使用 az cli 命令,我使用了以下命令:
blob=$(az storage blob list -c '$web' --account-name "$SA_NAME" --query "[].{name:name}" --output tsv)
prefix="mf"
for b in $blob
do
if [[ "$b" != "$prefix"* ]];
then
az storage blob delete -c '$web' --account-name "$SA_NAME" -n "$b"
fi
done
英文:
To continue using az cli commands, I used the following command
blob=$(az storage blob list -c '$web' --account-name "$SA_NAME" --query "[].{name:name}" --output tsv)
prefix="mf"
for b in $blob
do
if [[ "$b" != "$prefix"* ]];
then
az storage blob delete -c '$web' --account-name "$SA_NAME" -n "$b"
fi
done
答案3
得分: 0
我们可以使用以下命令来删除容器内的文件:
az storage blob delete-batch --account-key <storage_account_key> --account-name <storage_account_name> --source <container_name> --delete-snapshots include
英文:
We can use this command for deleting files inside the container.
az storage blob delete-batch --account-key <storage_account_key> --account-name <storage_account_name> --source <container_name> --delete-snapshots include
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论