Listing Buckets

This page shows you how to create Google Cloud Storage buckets. For an overview of buckets, read the Key Terms.

To list the buckets in a project:

Console

Open the Cloud Storage browser in the Google Cloud Platform Console.
Open the Cloud Storage browser

Buckets that are part of the currently selected project appear in the browser list.

gsutil

Use the gsutil ls command:

gsutil ls

The response looks like the following example:

gs://[BUCKET_NAME1]/
gs://[BUCKET_NAME2]/
gs://[BUCKET_NAME3]/
...

Client libraries

C#

For more on installing and creating a Cloud Storage client, refer to Cloud Storage Client Libraries.

private void ListBuckets()
{
    var storage = StorageClient.Create();
    foreach (var bucket in storage.ListBuckets(s_projectId))
    {
        Console.WriteLine(bucket.Name);
    }
}

Go

For more on installing and creating a Cloud Storage client, refer to Cloud Storage Client Libraries.

var buckets []string
it := client.Buckets(ctx, projectID)
for {
	battrs, err := it.Next()
	if err == iterator.Done {
		break
	}
	if err != nil {
		return nil, err
	}
	buckets = append(buckets, battrs.Name)
}

Java

For more on installing and creating a Cloud Storage client, refer to Cloud Storage Client Libraries.

Page<Bucket> buckets = storage.list(BucketListOption.pageSize(100),
    BucketListOption.prefix(prefix));
for (Bucket bucket : buckets.iterateAll()) {
  // do something with the bucket
}

Node.js

For more on installing and creating a Cloud Storage client, refer to Cloud Storage Client Libraries.

// Imports the Google Cloud client library
const Storage = require('@google-cloud/storage');

// Instantiates a client
const storage = Storage();

// Lists all buckets in the current project
storage
  .getBuckets()
  .then(results => {
    const buckets = results[0];

    console.log('Buckets:');
    buckets.forEach(bucket => {
      console.log(bucket.name);
    });
  })
  .catch(err => {
    console.error('ERROR:', err);
  });

PHP

For more on installing and creating a Cloud Storage client, refer to Cloud Storage Client Libraries.

use Google\Cloud\Storage\StorageClient;

/**
 * List all Cloud Storage buckets for the current project.
 *
 * @return void
 */
function list_buckets()
{
    $storage = new StorageClient();
    foreach ($storage->buckets() as $bucket) {
        printf('Bucket: %s' . PHP_EOL, $bucket->name());
    }
}

Ruby

For more on installing and creating a Cloud Storage client, refer to Cloud Storage Client Libraries.

# project_id = "Your Google Cloud project ID"

require "google/cloud/storage"

storage = Google::Cloud::Storage.new project: project_id

storage.buckets.each do |bucket|
  puts bucket.name
end

REST APIs

JSON API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Use cURL to call the JSON API with a LIST Bucket request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X GET -H "Authorization: Bearer [OAUTH2_TOKEN]" \
        "https://www.googleapis.com/storage/v1/b?project=[PROJECT_NAME]"

    You can use a prefix=[PREFIX] query string parameter to limit results to buckets that have the specified prefix.

XML API

  1. Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.
  2. Use cURL to call the XML API with a GET Service request, replacing [VALUES_IN_BRACKETS] with the appropriate values:
    curl -X GET -H "Authorization: Bearer [OAUTH2_TOKEN]" \
        -H "x-goog-project-id: [PROJECT_NAME]" \
        "https://storage.googleapis.com"

    You can use a prefix=[PREFIX] query string parameter to limit results to buckets that have the specified prefix.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Storage Documentation