gcloud storage cp [SOURCE …] DESTINATION [--additional-headers=HEADER=VALUE] [--all-versions, -A] [--no-clobber, -n] [--content-md5=MD5_DIGEST] [--continue-on-error, -c] [--daisy-chain, -D] [--do-not-decompress] [--include-managed-folders] [--manifest-path=MANIFEST_PATH, -L MANIFEST_PATH] [--preserve-posix, -P] [--print-created-message, -v] [--read-paths-from-stdin, -I] [--recursive, -R, -r] [--skip-unsupported, -U] [--storage-class=STORAGE_CLASS, -s STORAGE_CLASS] [--canned-acl=PREDEFINED_ACL, --predefined-acl=PREDEFINED_ACL, -a PREDEFINED_ACL --[no-]preserve-acl, -p] [--gzip-in-flight=[FILE_EXTENSIONS,…], -j [FILE_EXTENSIONS,…] | --gzip-in-flight-all, -J | --gzip-local=[FILE_EXTENSIONS,…], -z [FILE_EXTENSIONS,…] | --gzip-local-all, -Z] [--ignore-symlinks | --preserve-symlinks] [--decryption-keys=[DECRYPTION_KEY,…] --encryption-key=ENCRYPTION_KEY] [--cache-control=CACHE_CONTROL --content-disposition=CONTENT_DISPOSITION --content-encoding=CONTENT_ENCODING --content-language=CONTENT_LANGUAGE --content-type=CONTENT_TYPE --custom-time=CUSTOM_TIME --clear-custom-contexts | --custom-contexts=[CUSTOM_CONTEXTS_KEYS_AND_VALUES,…] | --custom-contexts-file=CUSTOM_CONTEXTS_FILE | --remove-custom-contexts=[CUSTOM_CONTEXTS_KEYS,…] --update-custom-contexts=[CUSTOM_CONTEXTS_KEYS_AND_VALUES,…] --clear-custom-metadata | --custom-metadata=[CUSTOM_METADATA_KEYS_AND_VALUES,…] | --remove-custom-metadata=[METADATA_KEYS,…] --update-custom-metadata=[CUSTOM_METADATA_KEYS_AND_VALUES,…]] [--if-generation-match=GENERATION --if-metageneration-match=METAGENERATION] [--retain-until=DATETIME --retention-mode=RETENTION_MODE] [GCLOUD_WIDE_FLAG …]
cp command does not follow directory
symlinks. You can use the --preserve-symlinks flag to follow
directory symlinks.
gcloud storage cp *.txt gs://my-bucketThe following command downloads all text files from a bucket to your current directory:
gcloud storage cp gs://my-bucket/*.txt .The following command transfers all text files from a bucket to a different cloud storage provider:
gcloud storage cp gs://my-bucket/*.txt s3://my-bucket
Use the --recursive option to copy an entire directory tree. The
following command uploads the directory tree
:
dir
gcloud storage cp --recursive dir gs://my-bucket
Recursive listings are similar to adding ** to a query, except
** matches only cloud objects and will not match prefixes. For
example, the following would not match
gs://my-bucket/dir/log.txt
gcloud storage cp gs://my-bucket/**/dir dir
** retrieves a flat list of objects in a single API call. However,
** matches folders for non-cloud queries. For example, a folder
would be copied in the following.
dir
gcloud storage cp ~/Downloads/**/dir gs://my-bucket
The contexts are preserved when copying to Google Cloud Storage. To overwrite
contexts on the destination object, use --custom-contexts or
--custom-contexts-file. For example:
gcloud storage cp gs://my-bucket/object gs://destination-bucket/object --custom-contexts=key1=value1,key2=value2SOURCE …]DESTINATION--additional-headers=HEADER=VALUEheader1=value1,header2=value2. Overrides
the default storage/additional_headers property value for this
command invocation.
--all-versions, -A--no-clobber, -n--content-md5=MD5_DIGEST--continue-on-error, -c--daisy-chain, -D--do-not-decompress--include-managed-folders--manifest-path=MANIFEST_PATH, -L MANIFEST_PATHIf the manifest file already exists, gcloud storage appends log items to the existing file.
Objects that are marked as "OK" or "skipped" in the existing manifest file are not retried by future commands. Objects marked as "error" are retried.--preserve-posix, -PFor uploads, these attributes are read off of local files and stored in the cloud as custom metadata. For downloads, custom cloud metadata is set as POSIX attributes on files after they are downloaded.
On Windows, this flag will only set and restore access time and modification time because Windows doesn't have a notion of POSIX UID, GID, and mode.--print-created-message, -v--read-paths-from-stdin, -I--recursive, -R, -r--skip-unsupported, -U--storage-class=STORAGE_CLASS, -s STORAGE_CLASS--canned-acl=PREDEFINED_ACL, --predefined-acl=PREDEFINED_ACL, -a PREDEFINED_ACL--[no-]preserve-acl, -p--preserve-acl to enable and
--no-preserve-acl to disable.
--gzip-in-flight=[FILE_EXTENSIONS,…], -j [FILE_EXTENSIONS,…]--gzip-in-flight option, files being uploaded
are compressed in-memory and on-the-wire only. Both the local files and Cloud
Storage objects remain uncompressed. The uploaded objects retain the
Content-Type and name of the original files.
--gzip-in-flight-all, -J--gzip-in-flight option described above, but it applies to all
uploaded files, regardless of extension.
CAUTION: If some of the source files don't compress well, such as binary data,
using this option may result in longer uploads.
--gzip-local=[FILE_EXTENSIONS,…], -z [FILE_EXTENSIONS,…]
When you specify the --gzip-local option, the data from files is
compressed before it is uploaded, but the original files are left uncompressed
on the local disk. The uploaded objects retain the Content-Type and
name of the original files. However, the Content-Encoding metadata
is set to gzip and the Cache-Control metadata set to
no-transform. The data remains compressed on Cloud Storage servers
and will not be decompressed on download by gcloud storage because of the
no-transform field.
--gzip-local-all, -Z--gzip-local option described above, but it applies to all uploaded
files, regardless of extension.
CAUTION: If some of the source files don't compress well, such as binary data,
using this option may result in files taking up more space in the cloud than
they would if left uncompressed.
Flags to influence behavior when handling symlinks. Only one value may be set.
At most one of these can be specified:
--ignore-symlinks--preserve-symlinksDirectory symlinks are only followed if this flag is specified.
CAUTION: No validation is applied to the symlink target paths. Once downloaded, preserved symlinks will point to whatever path was specified by the placeholder, regardless of the location or permissions of the path, or whether it actually exists.
This feature is not supported on Windows.--decryption-keys=[DECRYPTION_KEY,…]--encryption-key=ENCRYPTION_KEYprojects/{project}/locations/{location}/keyRings/{key-ring}/cryptoKeys/{crypto-key}.
The specified key also acts as a decryption key, which is useful when copying or
moving encrypted data to a new location. Using this flag in an objects
update command triggers a rewrite of target objects.
--cache-control=CACHE_CONTROL--content-disposition=CONTENT_DISPOSITION--content-encoding=CONTENT_ENCODINGgzip).
--content-language=CONTENT_LANGUAGEen signifies
"English").
--content-type=CONTENT_TYPEtext/html).
--custom-time=CUSTOM_TIME--clear-custom-contexts--custom-contexts=[CUSTOM_CONTEXTS_KEYS_AND_VALUES,…]--custom-contexts-file=CUSTOM_CONTEXTS_FILE1. The following JSON document shows two key value pairs, i.e. (key1, value1) and (key2, value2):
{ "key1": {"value": "value1"}, "key2": {"value": "value2"} }
2. The following YAML document shows two key value pairs, i.e. (key1, value1) and (key2, value2):
key1: value: value1 key2: value: value2
--clear-custom-contexts, --custom-contexts or
--custom-contexts-file. If --update-custom-contexts
and --remove-custom-contexts are specified together, the
--remove-custom-contexts would be applied first on object.
--remove-custom-contexts=[CUSTOM_CONTEXTS_KEYS,…]--update-custom-contexts=[CUSTOM_CONTEXTS_KEYS_AND_VALUES,…]--clear-custom-metadata--preserve-posix, POSIX attributes will still be stored in custom
metadata.
--custom-metadata=[CUSTOM_METADATA_KEYS_AND_VALUES,…]--preserve-posix,
POSIX attributes are also stored in custom metadata.
--custom-metadata or --clear-custom-metadata, but can
be specified together:
--remove-custom-metadata=[METADATA_KEYS,…]--update-custom-metadata. When used with
--preserve-posix, POSIX attributes specified by this flag are not
preserved.
--update-custom-metadata=[CUSTOM_METADATA_KEYS_AND_VALUES,…]--remove-custom-metadata. When keys overlap with those
provided by --preserve-posix, values specified by this flag are
used.
--if-generation-match=GENERATION--if-metageneration-match=METAGENERATION--retain-until=DATETIME--retention-mode=RETENTION_MODERETENTION_MODE must be one of: Locked,
Unlocked.
--access-token-file,
--account, --billing-project,
--configuration,
--flags-file,
--flatten, --format, --help, --impersonate-service-account,
--log-http,
--project, --quiet, --trace-token, --user-output-enabled,
--verbosity.
Run $ gcloud help for details.
gcloud alpha storage cp
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-05-27 UTC.