10

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

Graham Polley
  • 14,393
  • 4
  • 44
  • 80

2 Answers2

22

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 "/$"
rein
  • 32,967
  • 23
  • 82
  • 106
1

Just to add here, if you directly drag a folder tree to google cloud storage web GUI, then you don't really get a file for a parent folder, in fact each file name is a fully qualified url e.g. "/blah/foo/bar.txt" , instead of a folder blah>foo>bar.txt

The trick here is to first use the GUI to create a folder called blah and then create another folder called foo inside (using the button in the GUI) and finally drag the files in it.

When you now list the file you will get a separate entry for

  1. blah/
  2. foo/
  3. bar.txt

rather than only one

  1. blah/foo/bar.txt
varun
  • 4,522
  • 33
  • 28