mv - Move/rename objects

Synopsis

gsutil mv [-p] src_url dst_url
gsutil mv [-p] src_url... dst_url
gsutil mv [-p] -I dst_url

Description

The gsutil mv command allows you to move data between your local file system and the cloud, move data within the cloud, and move data between cloud storage providers. For example, to move all objects from a bucket to a local directory you could use:

gsutil mv gs://my_bucket/* dir

Similarly, to move all objects from a local directory to a bucket you could use:

gsutil mv ./dir gs://my_bucket

Renaming Groups Of Objects

You can use the gsutil mv command to rename all objects with a given prefix to have a new prefix. For example, the following command renames all objects under gs://my_bucket/oldprefix to be under gs://my_bucket/newprefix, otherwise preserving the naming structure:

gsutil mv gs://my_bucket/oldprefix gs://my_bucket/newprefix

Note that when using mv to rename groups of objects with a common prefix, you cannot specify the source URL using wildcards; you must spell out the complete name.

If you do a rename as specified above and you want to preserve ACLs, you should use the -p option (see OPTIONS).

If you have a large number of files to move you might want to use the gsutil -m option, to perform a multi-threaded/multi-processing move:

gsutil -m mv gs://my_bucket/oldprefix gs://my_bucket/newprefix

Non-Atomic Operation

Unlike the case with many file systems, the gsutil mv command does not perform a single atomic operation. Rather, it performs a copy from source to destination followed by removing the source for each object.

A consequence of this is that, in addition to normal network and operation charges, if you move a Nearline Storage, Coldline Storage, or Archive Storage object, deletion and data retrieval charges apply. See the documentation for pricing details.

Options

All options that are available for the gsutil cp command are also available for the gsutil mv command (except for the -R flag, which is implied by the gsutil mv command). Please see the OPTIONS sections of gsutil help cp for more information.