Skip to content

Instantly share code, notes, and snippets.

@fonylew
Created April 22, 2020 08:37
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save fonylew/480ab35656572c5341510b59785ac2e8 to your computer and use it in GitHub Desktop.
Save fonylew/480ab35656572c5341510b59785ac2e8 to your computer and use it in GitHub Desktop.
# Create a new Bucket
gsutil mb gs://[BUCKET]
# List files in bucket
gsutil ls gs://[BUCKET]
# Check bucket usage (du: disk usage)
gsutil du -sh gs://[BUCKET]
# Copy (upload) file to bucket
gsutil cp [File] gs://[BUCKET]
# > no need to create directory
gsutil cp [File] gs://[BUCKET]/path/to/file
# > copy (upload) directory
gsutil cp -r [Folder] gs://[BUCKET]
# > enable multiprocessing
gsutil -m cp -r [Folder] gs://[BUCKET]
# > copy (download) file
gsutil cp gs://[BUCKET]/path/to/file [File]
# > copy (download) directory to current local directory
gsutil -m cp -r gs://[BUCKET]/path .
# > copy (download) txt files to current local directory
gsutil -m cp gs://[BUCKET]/*.txt .
# Move or rename object
gsutil mv gs://[BUCKET]/path/to/old_name gs://[BUCKET]/path/to/new_name
# Remove file or directory
# > remove file
gsutil rm gs://[BUCKET]/path/to/file
# > remove directory
gsutil rm -r gs://[BUCKET]/path/to/directory
# Doc: https://cloud.google.com/storage/docs/how-to
@fonylew
Copy link
Author

fonylew commented Apr 22, 2020

@fonylew
Copy link
Author

fonylew commented Apr 22, 2020

Python uploading example: https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python

It requires a service account if it is not run on Google Cloud environment where default service account is supplied,
or
Set up Application Default Credentials for local developement: https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment