Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



ls - List providers, buckets, or objects

ls - List providers, buckets, or objects

Synopsis

gsutil ls [-a] [-b] [-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/**

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 MB)

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, 02 Mar 2012 19:25:17 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 MB)

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/ :
        StorageClass:                 STANDARD
        LocationConstraint:           US
        Versioning enabled:           True
        Logging:                      None
        WebsiteConfiguration:         None
        CORS configuration:           Present
        Lifecycle configuration:      None
[
  {
    "entity": "group-00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "entityId": "00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "role": "OWNER"
  }
]
        Default ACL:
[
  {
    "entity": "group-00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "entityId": "00b4903a97163d99003117abe64d292561d2b4074fc90ce5c0e35ac45f66ad70",
    "role": "OWNER"
  }
]

Options

-l Prints long listing (owner, length).
-L Prints even more detail than -l. This is a separate option because it makes additional service requests (so, takes longer and adds requests costs).
-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., 1KB, 234MB, 2GB, etc.)
-p proj_id Specifies the project ID to use for listing buckets.
-R , -r Requests a recursive listing.
-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.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.