Robin Alexander
Robin Alexander

Reputation: 1004

Overwrite files with s3cmd

I try to upload files to my S3 Bucket using the s3cmd. Works fine as it should, but files which already exist will not be overwritten but saved as a new file like "filename-1.ext".

I have found the

-f, --force (Force overwrite and other dangerous operations.)

command at http://s3tools.org/usage and tried

s3cmd put ~/Desktop/filename.ext  s3://mybucket -f

but files are still saved as new and not overwritten. Does anyone have any idea? Thanks for your help!

Upvotes: 5

Views: 5869

Answers (3)

koolhead17
koolhead17

Reputation: 1964

You can use mc (a.k.a. Minio client). It’s written in Golang & available under the Open Source Apache License. It is available for Mac, Linux, Windows, and FreeBSD. You can use the mc cp command to achieve your requirement.

mc GNU/Linux Download

64-bit Intel from https://dl.minio.io/client/mc/release/linux-amd64/mc
32-bit Intel from https://dl.minio.io/client/mc/release/linux-386/mc
32-bit ARM from https://dl.minio.io/client/mc/release/linux-arm/mc
$ chmod +x mc
$ ./mc --help

Configuring mc for Amazon S3

$ mc config host add mys3 https://s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
  • Replace with your access/secret key.
  • By default, mc uses signature version 4 of Amazon S3.
  • mys3 is Amazon S3 alias for minio client.

Overwrite your object name myfile.txt to Amazon S3 bucket name mybucket

./mc cp myfile.txt mys3/mybucket

Hope it helps.

Disclaimer: I work for Minio

Upvotes: 1

angst7
angst7

Reputation: 54

Delete the existing file first: s3cmd del s3://bucket/file then put the new file.

Upvotes: 1

John Rotenstein
John Rotenstein

Reputation: 270224

These days it is recommended to use the AWS Command-Line Interface (CLI).

It has an aws s3 cp command that always retains the requested name.

Upvotes: 1

Related Questions