← topics

>_ Cloud Storage gsutil

20 commands

Create a new Cloud Storage bucket

gsutil mb gs://BUCKET_NAME

List all Cloud Storage buckets accessible in the current project

gsutil ls

Upload a local file to a Cloud Storage bucket

gsutil cp FILE.TXT gs://BUCKET_NAME/

Download a file from Cloud Storage to the current directory

gsutil cp gs://BUCKET_NAME/FILE.TXT .

Delete an object from a Cloud Storage bucket

gsutil rm gs://BUCKET_NAME/FILE.TXT

Rename or move an object within Cloud Storage

gsutil mv gs://BUCKET_NAME/OLD.TXT gs://BUCKET_NAME/NEW.TXT

Remove an empty Cloud Storage bucket

gsutil rb gs://BUCKET_NAME

Print the contents of a Cloud Storage object to stdout

gsutil cat gs://BUCKET_NAME/FILE.TXT

Display the total size of a Cloud Storage bucket in human-readable format

gsutil du -sh gs://BUCKET_NAME

Display metadata for a specific Cloud Storage object

gsutil stat gs://BUCKET_NAME/FILE.TXT

Recursively upload an entire local directory to Cloud Storage

gsutil cp -r ./LOCAL_DIR/ gs://BUCKET_NAME/

Synchronise a local directory with a Cloud Storage bucket, copying only changed files

gsutil rsync -r ./LOCAL_DIR gs://BUCKET_NAME

Upload a directory to Cloud Storage using parallel multi-threaded transfers

gsutil -m cp -r ./DATA/ gs://BUCKET_NAME/

Enable object versioning on a Cloud Storage bucket

gsutil versioning set on gs://BUCKET_NAME

Apply a lifecycle configuration file to a Cloud Storage bucket

gsutil lifecycle set lifecycle.json gs://BUCKET_NAME

Grant a user the Storage Object Viewer role on a Cloud Storage bucket

gsutil iam ch user:USER@example.com:roles/storage.objectViewer gs://BUCKET_NAME

Apply a CORS configuration file to a Cloud Storage bucket

gsutil cors set cors.json gs://BUCKET_NAME

Generate a signed URL valid for 1 hour for a private Cloud Storage object

gsutil signurl -d 1h KEY.json gs://BUCKET_NAME/PRIVATE_FILE.TXT

Set a 365-day retention policy on a Cloud Storage bucket

gsutil retention set 365d gs://BUCKET_NAME

Copy CSV files to Cloud Storage, skipping any files that already exist at the destination

gsutil cp -n ./DATA/*.csv gs://BUCKET_NAME/DATA/

Ready to test yourself?

Practice these commands →