How do you delete multiple S3 files with Last Modified date condition?
I have this folder structure on s3.
- dentca-lab-dev-sample
- 2019-03-13
- file1 Last modified: Mar 13, 2019 2:34:06 PM GMT-0700
- file2 Last modified: Mar 13, 2019 3:18:01 PM GMT-0700
- file3 Last modified: Mar 13, 2019 2:34:30 PM GMT-0700
- file4 Last modified: Mar 13, 2019 2:32:40 PM GMT-0700
- 2019-03-13
and wanted to delete a file (this is just a sample) less than Mar 13, 2019 2:34:30 PM
and so I made this bash script but its not working.
aws s3 ls --recursive s3://dentca-lab-dev-sample/2019-03-13/ | awk '$1 <= "2019-03-13 14:34:30" {print $4}'
** ls is just for testing. will change it to rm
I also have this script for testing
aws s3 ls --recursive s3://dentca-lab-dev-sample/2019-03-13/
output:
2019-03-13 14:34:06 11656584 2019-03-13/mandibular.stl
2019-03-13 15:18:01 11969184 2019-03-13/maxillary.stl
2019-03-13 14:34:30 9169657 2019-03-13/obj.obj
2019-03-13 14:32:40 15690284 2019-03-13/upperAIO_50005.stl
but when I do the awk to make condition doesn't work. Maybe because $1 only catches this arugment 2019-03-13 and im compering it to 2019-03-13 14:34:30
also tried doing this.
awk '$1 $2 <= "2019-03-13 14:34:30" {print $4}' to catch the second argument but still got nothing. Its my first to make a bash btw.
Thank you! I have this as reference btw. aws cli s3 bucket remove object with date condition