Hands-On Machine Learning on Google Cloud Platform
上QQ阅读APP看书,第一时间看更新

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 gs://packt-gcp/

Let's analyze an option that is particularly useful: I refer to the -m flag. If you are performing a sequence of gsutil operations it may run significantly faster if you instead use gsutil -m -o, this means to run in parallel. This can significantly improve performance if you are performing operations on a large number of files over a reasonably fast network connection but may make performance worse if you are using a slower network.

The -m flag is particularly suited to the following commands: ls, mb, mv, rb, and du.