Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all public links for all objects in a bucket using gsutil

Is there a way to list all public links for all the objects stored into a Google Cloud Storage bucket (or a directory in a bucket) using Cloud SDK's gsutil or gcloud?

Something like:

$ gsutil ls --public-link gs://my-bucket/a-directory

like image 634
toomuchkevin Avatar asked Sep 21 '16 06:09

toomuchkevin


People also ask

What command is used to show a list of Cloud Storage buckets?

ls - List providers, buckets, or objects | Cloud Storage | Google Cloud.

How do I give a public access to a bucket in GCP?

In the Google Cloud console, go to the Cloud Storage Browser page. In the list of buckets, click on the name of the bucket that you want to make public. Select the Permissions tab near the top of the page. In the Permissions section, click the + Add button.

What is gsutil command?

gsutil is a Python application that lets you access Cloud Storage from the command line. You can use gsutil to do a wide range of bucket and object management tasks, including: Creating and deleting buckets. Uploading, downloading, and deleting objects.


1 Answers

Public links for publicly visible objects are predictable. They just match this pattern: https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME.

gsutil doesn't have a command to print URLs for objects in a bucket, but it can just list objects. You could pipe that to a program like sed to replace those listings with object names. For example:

gsutil ls gs://pub/** | sed 's|gs://|https://storage.googleapis.com/|'

The downside here is that this would produce links to all resources, not just those that are publicly visible. So you'd need to either know which resources are publicly visible, or you'd need to write a more elaborate filter based on gsutil ls -L.

like image 148
Brandon Yarbrough Avatar answered Oct 02 '22 14:10

Brandon Yarbrough