LinuxCommandLibrary

gsutil

Manage Google Cloud Storage buckets and objects

TLDR

List all buckets in a project you are logged into

$ gsutil ls
copy

List the objects in a bucket
$ gsutil ls -r 'gs://[bucket_name]/[prefix]**'
copy

Download an object from a bucket
$ gsutil cp gs://[bucket_name]/[object_name] [path/to/save_location]
copy

Upload an object to a bucket
$ gsutil cp [object_location] gs://[destination_bucket_name]/
copy

Rename or move objects in a bucket
$ gsutil mv gs://[bucket_name]/[old_object_name] gs://[bucket_name]/[new_object_name]
copy

Create a new bucket in the project you are logged into
$ gsutil mb gs://[bucket_name]
copy

Delete a bucket and remove all the objects in it
$ gsutil rm -r gs://[bucket_name]
copy

SYNOPSIS

gsutil [global-options] command [args]

PARAMETERS

-D
    Start debug log server on port 8080

-DD
    Start debug log server; use with port argument

-e class[,class...]
    Error trace for specified exception classes

-h HEADER:VALUE
    Add HTTP header to requests

-m
    Enable multi-threaded/multi-process for parallelism

-q
    Quiet mode; suppress non-error console output

-r|-R
    Recursive operation on directories

-s
    Single-threaded execution (disables -m)

-u
    Skip loading user config file

-v
    Verbose mode; enable logging

--
    Pass subsequent args to subcommand literally

--config-file FILE
    Use alternate boto config file

--debug_gcs
    Debug GCS requests

--no_crc32c
    Disable CRC32C checksum validation

--parallel_composite_upload_threshold N
    Threshold for parallel uploads (MB)

DESCRIPTION

gsutil is a Python-based command-line interface for interacting with Google Cloud Storage (GCS). It enables efficient management of buckets and objects, supporting operations like upload, download, copy, delete, and listing. Key features include parallel multi-threaded transfers (-m flag), ACL management, versioning, lifecycle rules, and resumable transfers for large files. gsutil mimics Unix utilities such as cp, mv, rm, and rsync, making it intuitive for Linux users.

Authentication uses OAuth 2.0 via gcloud auth or service account keys. It's installed via the Google Cloud SDK and configured through .boto or .boto2 files for advanced settings like encryption or proxies. Ideal for scripting, CI/CD pipelines, and data workflows, gsutil handles terabyte-scale transfers reliably. Use gsutil help for subcommand details; supports wildcards, ranges, and conditions for precise control.

CAVEATS

Requires Google Cloud SDK and authentication (gcloud auth login). Not installed by default on Linux. Large-scale use needs quota checks and IAM permissions. Debug flags (-D/-DD) expose tokens—use cautiously.

COMMON SUBCOMMANDS

cp: Copy objects.
ls: List buckets/objects.
mb: Make bucket.
rb: Remove bucket.
rm: Delete objects.
rsync: Sync directories.
du: Disk usage.
iam: Manage ACLs.

AUTHENTICATION

Run gcloud auth application-default login or use service account key: gcloud auth activate-service-account --key-file=KEY.json.

HISTORY

Developed by Google in 2009 as part of App Engine tools. Evolved with GCS launch (2010); integrated into Cloud SDK (2013). Python 3 support added in v4.0+; actively maintained for gcloud ecosystem.

SEE ALSO

gcloud(1), rsync(1), scp(1), curl(1)

Copied to clipboard