ls - List providers, buckets, or objects

ls - List providers, buckets, or objects

Synopsis

gsutil ls [-a] [-b] [-d] [-l] [-L] [-r] [-p proj_id] url...

Listing Providers, Buckets, Subdirectories, And Objects

If you run gsutil ls without URLs, it lists all of the Google Cloud Storage buckets under your default project ID:

gsutil ls

(For details about projects, see gsutil help projects and also the -p option in the OPTIONS section below.)

If you specify one or more provider URLs, gsutil ls will list buckets at each listed provider:

gsutil ls gs://

If you specify bucket URLs, gsutil ls will list objects at the top level of each bucket, along with the names of each subdirectory. For example:

gsutil ls gs://bucket

might produce output like:

gs://bucket/obj1.htm
gs://bucket/obj2.htm
gs://bucket/images1/
gs://bucket/images2/

The "/" at the end of the last 2 URLs tells you they are subdirectories, which you can list using:

gsutil ls gs://bucket/images*

If you specify object URLs, gsutil ls will list the specified objects. For example:

gsutil ls gs://bucket/*.txt

will list all files whose name matches the above wildcard at the top level of the bucket.

See gsutil help wildcards for more details on working with wildcards.

Directory By Directory, Flat, And Recursive Listings

Listing a bucket or subdirectory (as illustrated near the end of the previous section) only shows the objects and names of subdirectories it contains. You can list all objects in a bucket by using the -r option. For example:

gsutil ls -r gs://bucket

will list the top-level objects and buckets, then the objects and buckets under gs://bucket/images1, then those under gs://bucket/images2, etc.

If you want to see all objects in the bucket in one "flat" listing use the recursive ("**") wildcard, like:

gsutil ls -r gs://bucket/**

or, for a flat listing of a subdirectory:

gsutil ls -r gs://bucket/dir/**

If you want to see only the subdirectory itself, use the -d option:

gsutil ls -d gs://bucket/dir

Listing Object Details

If you specify the -l option, gsutil will output additional information about each matching provider, bucket, subdirectory, or object. For example:

gsutil ls -l gs://bucket/*.txt

will print the object size, creation time stamp, and name of each matching object, along with the total count and sum of sizes of all matching objects:

   2276224  2012-03-02T19:25:17Z  gs://bucket/obj1
   3914624  2012-03-02T19:30:27Z  gs://bucket/obj2
TOTAL: 2 objects, 6190848 bytes (5.9 MiB)

Note that the total listed in parentheses above is in mebibytes (or gibibytes, tebibytes, etc.), which corresponds to the unit of billing measurement for Google Cloud Storage.

You can get a listing of all the objects in the top-level bucket directory (along with the total count and sum of sizes) using a command like:

gsutil ls -l gs://bucket

To print additional detail about objects and buckets use the gsutil ls -L option. For example:

gsutil ls -L gs://bucket/obj1

will print something like:

gs://bucket/obj1:
        Creation time:                    Fri, 21 Oct 2016 19:25:17 GMT
        Update time:                      Fri, 21 Oct 2016 21:17:59 GMT
        Storage class update time:        Fri, 21 Oct 2016 22:12:32 GMT
        Size:                             2276224
        Cache-Control:                    private, max-age=0
        Content-Type:                     application/x-executable
        ETag:                             5ca6796417570a586723b7344afffc81
        Generation:                       1378862725952000
        Metageneration:                   1
        ACL:
[
  {
    "entity": "group-00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "entityId": "00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "role": "OWNER"
  }
]
TOTAL: 1 objects, 2276224 bytes (2.17 MiB)

Note that some fields above (time updated, storage class update time) are not available with the (non-default) XML API.

Also note that the Storage class update time field only appears if it differs from Creation time.

See also gsutil help acl for getting a more readable version of the ACL.

Listing Bucket Details

If you want to see information about the bucket itself, use the -b option. For example:

gsutil ls -L -b gs://bucket

will print something like:

gs://bucket/ :
        Storage class:                MULTI_REGIONAL
        Location constraint:          US
        Versioning enabled:           True
        Logging configuration:        None
        Website configuration:        None
        CORS configuration:           Present
        Lifecycle configuration:      None
        Labels:                       None
        Time created:                 Fri, 21 Oct 2016 19:25:17 GMT
        Time updated:                 Fri, 21 Oct 2016 21:17:59 GMT
        Metageneration:               1
        ACL:
[
  {
    "entity": "group-00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "entityId": "00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "role": "OWNER"
  }
]
        Default ACL:
[
  {
    "entity": "group-00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "entityId": "00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "role": "OWNER"
  }
]

Note that some fields above (time created, time updated, metageneration) are not available with the (non-default) XML API.

Options

-l Prints long listing (owner, length).
-L Prints even more detail than -l. Note: If you use this option with the (non-default) XML API it will generate an additional request per object being listed, which makes the -L option run much more slowly (and cost more) using the XML API than the default JSON API.
-d List matching subdirectory names instead of contents, and do not recurse into matching subdirectories even if the -R option is specified.
-b Prints info about the bucket when used with a bucket URL.
-h When used with -l, prints object sizes in human readable format (e.g., 1 KiB, 234 MiB, 2 GiB, etc.)
-p proj_id Specifies the project ID to use for listing buckets.
-R, -r Requests a recursive listing, performing at least one listing operation per subdirectory. If you have a large number of subdirectories and do not require recursive-style output ordering, you may be able to instead use wildcards to perform a flat listing, e.g. gsutil ls gs://mybucket/**, which generally performs fewer listing operations.
-a Includes non-current object versions / generations in the listing (only useful with a versioning-enabled bucket). If combined with -l option also prints metageneration for each listed object.
-e Include ETag in long listing (-l) output.

Send feedback about...

Cloud Storage Documentation