du - Display object size usage
Synopsis
gsutil du url...
Description
The du command displays the amount of space in bytes used up by the
objects in a bucket, subdirectory, or project. The syntax emulates
the Linux du -b
command, which reports the disk usage of files and subdirectories.
For example, the following command reports the total space used by all objects and
subdirectories under gs://your-bucket/dir:
gsutil du -s -a gs://your-bucket/dir
Options
- -0
Ends each output line with a 0 byte rather than a newline. You can use this to make the output machine-readable.
- -a
Includes both live and noncurrent object versions. Also prints the generation and metageneration number for each listed object. If this flag is not specified, only live object versions are included.
- -c
Includes a total size at the end of the output.
- -e
Exclude a pattern from the report. Example: -e "*.o" excludes any object that ends in ".o". Can be specified multiple times.
- -h
Prints object sizes in human-readable format. For example,
1 KiB
,234 MiB
, or2GiB
.- -s
Displays only the total size for each argument, omitting the list of individual objects.
- -X
Similar to
-e
, but excludes patterns from the given file. The patterns to exclude should be listed one per line.
Examples
To list the size of each object in a bucket:
gsutil du gs://bucketname
To list the size of each object in the prefix
subdirectory:
gsutil du gs://bucketname/prefix/*
To include the total number of bytes in human-readable form:
gsutil du -ch gs://bucketname
To see only the summary of the total number of (live) bytes in two given buckets:
gsutil du -s gs://bucket1 gs://bucket2
To list the size of each object in a bucket with Object Versioning enabled, including noncurrent objects:
gsutil du -a gs://bucketname
To list the size of each object 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 list the size of each bucket in a project and the total size of the project:
gsutil -o GSUtil:default_project_id=project-name du -shc