This page shows you how to list the objects stored in your Cloud Storage buckets, which are ordered in the list lexicographically by name.
Before you begin
To get the permissions that you need to list objects, ask your administrator
to grant you the Storage Object Viewer (roles/storage.objectViewer
)
IAM role for the bucket that contains the objects you want to
list. If you want to list objects within managed folders, you can grant
roles/storage.objectViewer
on the managed folder that contains the objects
you want to view instead of the bucket.
If you plan on using the Trusted Cloud console to perform the tasks on this page,
ask your administrator to grant you the Viewer (roles/viewer
) basic role in
addition to the Storage Object Viewer (roles/storage.objectViewer
) role.
These roles contain the permissions required to list objects. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
storage.objects.list
storage.buckets.list
- This permission is only needed if you want to use the Trusted Cloud console to perform the tasks on this page.
You can also get these permissions with other predefined roles or custom roles.
For information about granting roles for buckets, see Use IAM with buckets.
List the objects in a bucket
Console
- In the Trusted Cloud console, go to the Cloud Storage Buckets page.
In the bucket list, click the name of the bucket whose contents you want to view.
Command line
Use the gcloud storage ls
command:
gcloud storage ls gs://BUCKET_NAME
Where:
BUCKET_NAME
is the name of the bucket that contains the objects you want to list. For example,my-bucket
.
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:
For more information, see the
Cloud Storage Go API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:
For more information, see the
Cloud Storage Ruby API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
Before running code samples, set the The following sample lists all objects in a bucket: The following sample lists objects with a given prefix:C++
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
C#
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Go
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Java
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Node.js
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
PHP
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Python
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
Ruby
GOOGLE_CLOUD_UNIVERSE_DOMAIN
environment
variable to s3nsapis.fr
.
REST APIs
JSON API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorization
header.Use
cURL
to call the JSON API with a request to list objects:curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.s3nsapis.fr/storage/v1/b/BUCKET_NAME/o"
Where
BUCKET_NAME
is the name of the bucket whose objects you want to list. For example,my-bucket
.
XML API
Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorization
header.Use
cURL
to call the XML API with aGET
Bucket request:curl -X GET -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://storage.s3nsapis.fr/BUCKET_NAME?list-type=2"
Where
BUCKET_NAME
is the name of the bucket whose objects you want to list. For example,my-bucket
.You can use a
prefix=PREFIX
query string parameter to limit results to objects that have the specified prefix.
List the objects in a folder
Console
- In the Trusted Cloud console, go to the Cloud Storage Buckets page.
In the bucket list, click the name of the bucket that contains the folder.
In the Objects tab of the Bucket details page, click the name of the folder whose contents you want to view.
Command line
Use the gcloud storage ls
command to list the objects in a folder:
gcloud storage ls gs://BUCKET_NAME/FOLDER_NAME
Where:
BUCKET_NAME
is the name of the bucket that contains the folder. For example,my-bucket
.FOLDER_NAME
is the name of the folder that contains the objects you want to list. For example,my-folder
.
REST APIs
JSON API
To list the objects in a folder, use a list objects request
with the prefix
and delimiter
parameters. When the prefix
parameter is set, the list operation is scoped to only return objects
and folders under the prefix. When the delimiter
parameter is set,
the prefixes[]
list in the response populates with the names of
folders under the specified prefix.
For example:
To list all objects in the folder
image/
within the bucketmy-bucket
, use the following URL:"https://storage.s3nsapis.fr/storage/v1/b/my-bucket/o?prefix=image&delimiter=/"
.This could return the objects
my-bucket/image/cat.jpeg
andmy-bucket/image/dog.jpeg
.To include objects in subfolders within
image/
, remove thedelimiter
parameter:"https://storage.s3nsapis.fr/storage/v1/b/my-bucket/o?prefix=image"
.This could return the objects
my-bucket/image/cat.jpeg
,my-bucket/image/dog.jpeg
, andmy-bucket/image/dog/shiba.jpeg
.
To use wildcards in your list objects request and match objects by
glob expression, use the matchGlob
parameter. For example, matchGlob=**.jpeg
matches all
objects that end in .jpeg
. When you use matchGlob
, you must set
delimiter
to /
.
For example, use the following URL to match all objects within the
folder image
that end in .jpeg
:
"https://storage.s3nsapis.fr/storage/v1/b/my-bucket/o?prefix=image&delimiter=/&matchGlob=**.jpeg"
For more details about using parameters to filter for objects, see the Objects list JSON API reference documentation.
Use case
Using prefix
to list the contents of a folder can be useful for
when you only have the permission to list objects in the folder, but not
the whole bucket. For example, say you have the Storage Object Viewer
(roles/storage.objectViewer
) IAM
role for the managed folder my-bucket/my-managed-folder-a/
, but
not for the managed folder my-bucket/my-managed-folder-b/
. To return
only the objects in my-managed-folder-a
, you can specify
prefix=my-managed-folder-a/
.
Filtering objects
When listing objects, you can use prefixes or suffixes in your list request to filter objects by name.
Console
See filtering and sorting for information on how to filter and sort objects in buckets or folders.
Command line
You can use wildcards in your gcloud storage ls
command to
filter objects by prefix or suffix. For example, the following command
only lists objects in the bucket my-bucket
whose name begins with
image
and ends with .png
:
gcloud storage ls gs://my-bucket/image*.png
If the request is successful, the response looks similar to the following:
gs://my-bucket/image.png gs://my-bucket/image-dog.png gs://my-bucket/image-cat.png ...
You can use double-star wildcards to match zero or more folder levels in
a path. For example, the following command only lists objects whose name
ends in .jpeg
in any folder or subfolder within the bucket my-bucket
:
gcloud storage ls gs://my-bucket/**/*.jpeg
If the request is successful, the response looks similar to the following:
gs://my-bucket/puppy.jpeg gs://my-bucket/pug.jpeg gs://my-bucket/pets/dog.jpeg ...
REST APIs
See list objects in folders for information on how to filter objects by folder or object name prefix.
Performance considerations when listing objects
The underlying structure of buckets with hierarchical namespace enabled influences the performance of the listing objects operation, when compared to flat namespace buckets. For more information, see Optimize performance in buckets with hierarchical namespace enabled.
What's next
- Download an object from your bucket.
- View and edit object metadata.
- Delete objects from your bucket.
- Learn how to paginate results.