Google Cloud Storage
List object generations in Google Cloud Storage
Use the JSON API or gcloud storage ls to inspect object versions and generations in a bucket. Keep the version flag explicit when reconciling historical objects.
Documentation reviewed · 2 methods with sources
Ways to do it
API
GET /storage/v1/b/{bucket}/o?versions=true
List objects in a bucket with version entries and continue with pageToken.
Read source: Cloud Storage objects.list reference- Requirements
- A Google Cloud project, storage.objects.list permission on the bucket, OAuth or service-account credentials, and the bucket name.
- Limitations
- The versions and softDeleted parameters are mutually exclusive. softDeleted only works when the bucket has a soft delete policy.
Example shell
curl --fail -H "Authorization: Bearer $GOOGLE_ACCESS_TOKEN" "https://storage.googleapis.com/storage/v1/b/$BUCKET/o?versions=true&maxResults=100"CLI
gcloud storage ls --all-versions
List a bucket or object path from the Cloud SDK and include all object generations.
Read source: gcloud storage ls reference- Requirements
- The gcloud CLI authenticated to a project with permission to list the bucket and a bucket URI such as gs://example-bucket.
- Limitations
- Use --recursive when you need objects below nested prefixes. Use --json for machine-readable metadata.
Example shell
gcloud storage ls --all-versions --recursive --json "gs://$BUCKET"