google-cloud-platformgoogle-cloud-storagegsutil

Rename a folder in GCS using gsutil


I can't rename an existing folder in GCS. How do I do this?

As per the documentation, this should be:

gsutil mv gs://my_bucket/olddir gs://my_bucket/newdir

However, what happens is that olddir is placed under newdir, i.e the directory structure is like this (after the call to gsutil mv):

my_bucket
    newdir
        olddir

instead of (what I would expect)

my_bucket
    newdir

I've tried all four combinations of putting trailing slashes or not, but none of them worked.


Solution

  • This is a confirmed bug in GCS, see https://issuetracker.google.com/issues/112817360

    It actually only happens, when the directory name of newdir is a substring of olddir. So the gsutil call from the question actually works, but the following one would not:

    gsutil mv gs://my-organization-empty-bucket/dir_old gs://my-organization-empty-bucket/dir