3

I want to find the size of my sub-folders at the first depth in Google Cloud Storage. There is the function gsutil du, that is quite similar to du, but with some differences.

I am not able to just show the size of the sub-folders at the first depth. Using traditional du, I could use (from this stack):

du -h --max-depth=1
du -sh -- *

What is the equivalent with gsutil du? Doing gsutil du -h gs://bucket_name/* prints info for all sub-folders (many depths) while gsutil du -sh gs://bucket_name/* shows only grand total.

Thanks!

2 Answers 2

4

The command

gsutil ls -l gs://bucket_name/folder_name | xargs -I{} gsutil du -sh  {}

should do the trick.

1
  • are you sure about the -l flag? It seems to produce too much output which will induce du into error with message like InvalidUrlError: Unrecognized scheme "48 2023-06-04t13:02:09z gs" ?
    – Matifou
    Commented Aug 26, 2023 at 10:05
0

There's no --max-depth support in gsutil du. You could write a script that lists the first-level folder names, and then iterate over those folders and run gsutil ls -l $folder/*

1
  • yes, I was thinking an alternative would be something like gsutil ls | but I am not fluent enough in xargs and colleagues :-(
    – Matifou
    Commented Oct 24, 2019 at 21:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .