gsutil cheatsheet

The following is a list of the most-used commands that we can issue via gsutil:

  • Creating a bucket named packt-gcp:
    • gsutil mb gs://packt-gcp
  • Uploading a file to the bucket:

    • gsutil cp gs://packt-gcp/
  • Creating a subfolder in the bucket:
    • gsutil cp your-file gs://packt-gcp/
  • Listing the folder:
    • gsutil ls gs://packt-gcp/
  • Getting help on gsutil commands:
    • gsutil help
  • How much storage are we using (the -h makes it readable):
    • gsutil du -h gs://packt-gcp/
  • Copying a whole folder to a bucket:
    • gsutil cp -r gs://packt-gcp/

For instance, I have a local ./img directory with some images. I can copy the whole directory and create the bucket subdirectory at the same time with the following command:

gsutil cp -r ./img ...

Get Hands-On Machine Learning on Google Cloud Platform now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.