stat - Display object status
gsutil stat url...
The stat command will output details about the specified object URLs. It is similar to running:
gsutil ls -L gs://some-bucket/some-object
but is more efficient because it avoids performing bucket listings and gets the minimum necessary amount of object metadata. Moreover, because it avoids performing bucket listings (which are eventually consistent) the gsutil stat command provides a strongly consistent way to check for the existence (and read the metadata) of an object.
The gsutil stat command will, however, perform bucket listings if you specify URLs using wildcards.
If run with the gsutil -q option nothing will be printed, e.g.:
gsutil -q stat gs://some-bucket/some-object
This can be useful for writing scripts, because the exit status will be 0 for an existing object and 1 for a non-existent object.
Note: Unlike the gsutil ls command, the stat command does not support operations on sub-directories. For example, if you run the command:
gsutil -q stat gs://some-bucket/some-subdir/
gsutil will look for information about an object called "some-subdir/" (with a trailing slash) inside the bucket "some-bucket", as opposed to operating on objects nested under gs://some-bucket/some-subdir/. Unless you actually have an object with that name, the operation will fail. However, you can use the stat command on objects within subdirectories. For example, this command will work as expected:
gsutil -q stat gs://some-bucket/some-subdir/file.txt