Search code examples
aws-clis3cmd

Looking for AWS CLI equivalent for s3cmd --delete-removed


I'm moving from s3cmd tool to the official aws CLI tool distributed by Amazon, and as I'm converting old scripts, I'm curious about how to construct this equivalent command:

s3cmd --delete-removed sync s3://$BUCKET $LOCAL_DIR/

From the s3cmd documentation, I see that --delete-removed is defined as: Delete remote objects with no corresponding local file.

However, which is considered the remote and which is considered the local here? I am worried that the aws s3 sync command with the --delete flag will not be render the same results.

Are

s3cmd --delete-removed sync s3://$BUCKET $LOCAL_DIR/

and

aws s3 sync s3://$BUCKET $LOCAL_DIR/ --delete

the same commands?

Thank you for your help in untangling my confusion!


Solution

  • It looks that they are the same.

    Based on the aws cli s3 sync documentation,

    --delete (boolean) Files that exist in the destination but not in the source are deleted during sync

    So in your case,

    aws s3 sync s3://$BUCKET $LOCAL_DIR/ --delete
    

    will copy all files in s3://$BUCKET to $LOCAL_DIR/, but delete files in $LOCAL_DIR/ if they don't exist in s3://$BUCKET

    Check under the example section for an example of this