You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/storage/blobs/blob-cli.md
+50-24Lines changed: 50 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ author: StevenMatthew
7
7
ms.author: shaas
8
8
ms.service: azure-blob-storage
9
9
ms.topic: how-to
10
-
ms.date: 05/08/2024
10
+
ms.date: 06/11/2024
11
11
ms.devlang: azurecli
12
12
ms.custom: devx-track-azurecli
13
13
---
@@ -104,24 +104,24 @@ az storage blob upload-batch \
104
104
105
105
By default, the `az storage blob list` command lists all blobs stored within a container. You can use various approaches to refine the scope of your search. There's no restriction on the number of containers or blobs a storage account can have. To potentially avoid retrieving thousands of blobs, it's a good idea to limit the amount of data returned.
106
106
107
-
Use the `--prefix` parameter to select either a single known file or a range of files whose names begin with a defined string.
107
+
Use the `--prefix` parameter to select either a single known file or a range of files whose names begin with a defined string. You can specify a virtual directory as part of the `--prefix` parameter.
108
108
109
-
By default, only blobs are returned in a listing operation. In some scenarios, you might want to pass a value for the `--include` parameter to return additional types of objects such as soft-deleted blobs, snapshots, and versions. These values can be combined to return more than multiple object types.
109
+
By default, only blobs are returned in a listing operation. In some scenarios, you might want to pass a value for the `--include` parameter to return additional types of objects such as soft-deleted blobs, snapshots, and versions. These values can be combined to return multiple object types.
110
110
111
-
The `--num-results` parameter can be used to limit the number of unfiltered blobs returned from a container. A service limit of 5,000 is imposed on all Azure resources. This limit ensures that manageable amounts of data are retrieved and that performance isn't impacted. If the number of blobs returned exceeds either the `--num-results` value or the service limit, a continuation token is returned. This token allows you to use multiple requests to retrieve any number of blobs. More information is available on [Enumerating blob resources](/rest/api/storageservices/enumerating-blob-resources).
111
+
The `--num-results` parameter can be used to limit the number of blobs returned from a container. A service limit of 5,000 is imposed on all Azure resources. This limit ensures that manageable amounts of data are retrieved and that performance isn't impacted. If the number of blobs returned exceeds either the `--num-results` value or the service limit, a continuation token is returned. This token allows you to use multiple requests to retrieve any number of blobs. More information is available on [Enumerating blob resources](/rest/api/storageservices/enumerating-blob-resources).
112
112
113
-
The following example shows several approaches used to provide a list of blobs. The first approach lists a single blob within a specific container resource. The second approach uses the `--prefix` parameter to list all blobs in all containers with a prefix of *louis*. The search is restricted to five containers using the `--num-results` parameter. The third approach uses `--num-results`and `--marker`parameters to limit the retrieval of all blobs within a container.
113
+
The following example shows several approaches used to provide a list of blobs. The first approach lists all blobs within a specified container. The second approach uses the `--prefix` parameter to list all blobs in the containers that begin with the specified prefix.The third approach uses the `--num-results` parameter to limit the results returned and the `--show-next-marker`parameter to include the continuation token in the results. When a continuation token is present in the results, it is passed to the subsequent call to `az storage blob list` to retrieve the next set of results.
114
114
115
115
For more information, see the [az storage blob list](/cli/azure/storage/blob#az-storage-blob-list) reference.
116
116
117
117
```azurecli-interactive
118
118
#!/bin/bash
119
119
storageAccount="<storage-account>"
120
-
containerName="demo-container"
121
-
blobPrefix="img-louis"
120
+
containerName="<container-name>"
121
+
blobPrefix="<prefix-string>"
122
122
numResults=5
123
123
124
-
#Approach 1: List all blobs in a container
124
+
#Approach 1: List all blobs in a container by name.
125
125
126
126
az storage blob list \
127
127
--account-name $storageAccount \
@@ -130,7 +130,7 @@ az storage blob list \
130
130
--auth-mode login \
131
131
--output tsv
132
132
133
-
#Approach 2: Use the --prefix parameter to list blobs starting with specified prefix
133
+
#Approach 2: Use the --prefix parameter to list blobs starting with specified prefix.
134
134
135
135
az storage blob list \
136
136
--account-name $storageAccount \
@@ -140,22 +140,48 @@ az storage blob list \
140
140
--auth-mode login \
141
141
--output tsv
142
142
143
-
#Approach 3: Use the continuation token to return the next set of blobs.
144
-
145
-
$resultSet=$(az storage blob list `
146
-
--account-name $storageAccount `
147
-
--container $containerName `
148
-
--prefix $blobPrefix `
149
-
--num-results $numResults `
150
-
--show-next-marker `
151
-
--query "[].{Name:name, Marker:nextMarker}" `
152
-
--auth-mode login `
153
-
--output tsv)
154
-
155
-
$markerEntry=$resultSet[$numResults] | cut -f2
156
-
$marker= echo $markerEntry | cut -f2
157
-
143
+
#Approach 3: Use the continuation token to return the complete set of results.
158
144
145
+
get_blobs() {
146
+
if [ -z "$nextMarker" ]; then
147
+
az storage blob list --container-name $containerName --num-results $numResults --account-name $storageAccount --show-next-marker --only-show-errors --auth-mode login
148
+
else
149
+
az storage blob list --container-name $containerName --num-results $numResults --marker $nextMarker --account-name $storageAccount --show-next-marker --only-show-errors --auth-mode login
0 commit comments