Search code examples
amazon-web-servicesamazon-s3amazon-ec2aws-clibucket

AWS CLI move all files with condition


I must move into another bucket only files changed in the year 2015. How can I write this condition?

aws s3 mv <condition??> s3://bucket1 s3://bucket2 --recursive

Solution

  • I don't think you can directly do that through through the s3 option. what you can do though is a 2 steps approach:

    1. get the list of files that have been modified after a date

      aws s3api list-objects --bucket bucket1" --query 'Contents[?LastModified > `2015-01-01`].[Key]' --output text
      
    2. Based on this list you can move the items.

    I have not tried and not an shell expert but something around this

    aws s3api list-objects --bucket "<YOUR_BUCKET>" --query 'Contents[?LastModified > `2015-01-01`].[Key]' --output text | xargs aws s3 mv s3://bucket2/ -