✓ Solved

How Do I Rename Files/Object Storage

Hello. I seem to have inadvertently uploaded a lot of files to one of my buckets in Object storage that have their file names in All Caps. I need to somehow change all of these to lowercase file names. What is the best way to do this? I would prefer to just mass-change all of the files, rather than manually change them all. Is there a program that can accomplish this?

2 Replies

✓ Best Answer

From experience it can be tough to correct a naming scheme issue within Object Storage once you've already started uploading files. This is because you need to re-write the file(s) in question with a new name since objects in Object Storage cannot be modified at the block level.

With that said I think you are on the right track here and could run a script of some sort.

After a little bit of fussing around this definitely looks like something you should be able to do with a for loop of some sort. I came up with a simple version (see below) to get started. It's not pretty, but I was able to use s3cmd to copy the files in a given bucket and force the new file name to be all lowercase.

for i in $(s3cmd ls s3://BUCKETNAME | awk '{print $4}'); do s3cmd cp $i `echo $i | tr 'A-Z' 'a-z'`; done

I highly recommend testing this out on a sample bucket with a smaller batch of test files to ensure that this meets your use-case and does not cause any issues on your back-end. This is especially true if you will be changing a large number of files in the bucket.

Lastly, the loop I provided will leave some additional work on your end in its current form. The original files with the mixed-case naming will still exist, so you will need to manually remove them at your convenience (maybe using an s3 compatible tool with a GUI like Cyberduck so you can more easily remove extraneous objects) or cook up additional commands to do this for you.

I hope this helps get you headed in the right direction!

Wow, Josh! Thank you so much!

I just wanted to take a moment to extend my appreciation for such an extensive and helpful response. I did solve my issue! Unfortunately, the above solution did not end up being the best method for me (I had some additional problems with the stuff I uploaded so, for me, ultimately it just made sense to start from scratch. Sucks to be me. ha!).

Nevertheless, I was very impressed with your suggestions and I continue to be truly happy with Linode and certainly the customer service offered. I really scoured the web for an answer to this problem before posting here. Nothin'. Nowhere. I seriously thought that this would be a more common problem.

So, I'm certain that some other poor sap like me will be overjoyed to find this solution in the future! Thank you again for the quick response!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct