It isn’t easy to count how many files there are in each of your Google Cloud Storage (GCS) buckets. The console interface doesn’t readily surface this information, and using gcloud necessitates manually entering into each of the folders.
Luckily, we can use some simple shell scripting to find the total number of objects in each bucket. Here is a simple shell script that will list out all of your Google Cloud Storage buckets along with how many objects are contained in them.
You will need to have the gcloud utility installed, and be logged into the correct project for this to work. Then you can run the below in your terminal or in Cloud Shell:
The grep in the middle of the pipe command is to remove any subfolders from the total count, although any actual files within those subfolders are counted.