[GCS] Google Cloud Storageの総使用量をコマンドラインから確認する

Google Cloud Storageには、通常のレンタルサーバーのように「使用量」の表示がありません。そこで、Google Cloud Storage用コマンドラインツール「gsutil」を使って、ストレージの使用量を確認してみます。


gsutil -o GSUtil:default_project_id=プロジェクトID du -shc

27.46 KiB   gs://cdn.revdev.work
0 B   gs://test-revdev-work
27.46 KiB    total


gsutil du gs://バケット名

13636       gs://バケット名/test.jpg


gsutil du -ch gs://バケット名

13.32 KiB   gs://バケット名/test.jpg
13.32 KiB   total


gsutil du -e "*.jpg" -0 gs://バケット名



gsutil help du

  du - Display object size usage


  gsutil du url...

  The du command displays the amount of space (in bytes) being used by the
  objects in the file or object hierarchy under a given URL. The syntax emulates
  the Linux du command (which stands for disk usage). For example, the command:

  gsutil du -s gs://your-bucket/dir

  will report the total space used by all objects under gs://your-bucket/dir and
  any sub-directories.

  -0          Ends each output line with a 0 byte rather than a newline. This
              can be useful to make the output more easily machine-readable.

  -a          Includes non-current object versions / generations in the listing
              (only useful with a versioning-enabled bucket). Also prints
              generation and metageneration for each listed object.

  -c          Includes a grand total at the end of the output.

  -e          A pattern to exclude from reporting. Example: -e "*.o" would
              exclude any object that ends in ".o". Can be specified multiple

  -h          Prints object sizes in human-readable format (e.g., 1 KiB,
              234 MiB, 2GiB, etc.)

  -s          Displays only the grand total for each argument.

  -X          Similar to -e, but excludes patterns from the given file. The
              patterns to exclude should be one per line.

  To list the size of all objects in a bucket:

    gsutil du gs://bucketname

  To list the size of all objects underneath a prefix:

    gsutil du gs://bucketname/prefix/*

  To print the total number of bytes in a bucket, in human-readable form:

    gsutil du -ch gs://bucketname

  To see a summary of the total bytes in the two given buckets:

    gsutil du -s gs://bucket1 gs://bucket2

  To list the size of all objects in a versioned bucket, including objects that
  are not the latest:

    gsutil du -a gs://bucketname

  To list all objects in a bucket, except objects that end in ".bak",
  with each object printed ending in a null byte:

    gsutil du -e "*.bak" -0 gs://bucketname

  To get a total of all buckets in a project with a grand total for an entire

      gsutil -o GSUtil:default_project_id=project-name du -shc

Google Clould Storageは、米国リージョンなら5GBまで無料なので、ストレージだけを使っている場合は、GCPコンソールの予算メニューから「予算の設定」で1円以上になったらアラートするように設定しておくのもありですね。