Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gsutil - is it possible to list only folders?

Is it possible to list only the folders in a bucket using the gsutil tool?

I can't see anything listed here.

For example, I'd like to list only the folders in this bucket:

enter image description here

like image 547
Graham Polley Avatar asked Sep 22 '15 08:09

Graham Polley


People also ask

Does gsutil CP create folder?

You cannot create folders with gsutil as gsutil does not support it (workaround see below). However, it is supported via: UI in browser. write your own GCS client (we have written our own custom client which can create folders)

How do I list files in a GCS bucket?

List the objects in a bucket. In the Google Cloud console, go to the Cloud Storage Buckets page. In the bucket list, click on the name of the bucket whose contents you want to view. Optionally, use filtering to narrow the results in your list.

What is the difference between gcloud and gsutil?

"gcloud" can create and manage Google Cloud resources while "gsutil" cannot do so. "gsutil" can manipulate buckets, bucket's objects and bucket ACLs on GCS(Google Cloud Storage) while "gcloud" cannot do so.

What is GS in gsutil?

gsutil uses the prefix gs:// to indicate a resource in Cloud Storage: gs:// BUCKET_NAME / OBJECT_NAME. In addition to specifying exact resources, gsutil supports the use of wildcards in your commands.


1 Answers

Folders don't actually exist. gsutil and the Storage Browser do some magic under the covers to give the impression that folders exist.

You could filter your gsutil results to only show results that end with a forward slash but this may not show all the "folders". It will only show "folders" that were manually created (i.e., not implicitly exist because an object name contains slashes):

gsutil ls gs://bucket/ | grep -e "/$"
like image 103
rein Avatar answered Sep 27 '22 19:09

rein