I am trying to copy the latest file based on Last Modified from AWS S3 Folder_Test1 folder to a Folder_Test2 folder in the same bucket and using exclude and include in the copy command.
Folder_Test1:
Name Last Modified
T1_abc_june21.csv June 21,2020 9:27:03 AM GMT-0700
T1_abc_june21.csv June 21,2020 7:40:15 PM GMT-0700
T1_abc_june21.csv June 21,2020 9:20:32 PM GMT-0700
T1_abc_june25.csv June 25,2020 10:23:30 PM GMT-0700
T2_abc_june29.csv June 29,2020 6:15:12 AM GMT-0700
T2_abc_june29.csv June 29,2020 5:12:15 PM GMT-0700 (Fetch this object)
T1_abc_def_june21.csv June 21,2020 6:13:15 PM GMT-0700
T2_abc_def_june25.csv June 25,2020 5:33:10 AM GMT-0700
T3_abc_def_june25.csv June 25,2020 9:31:15 PM GMT-0700 (Fetch this object)
I have to filter the file name having only the latest file of abc and exclude the copy files:
I tried:
Step 1 Copy abc files from Folder_Test1 to Folder_Test2:
aws s3 cp s3://$bucket/Folder_Test1/ s3://$bucket/Folder_Test2/ --recursive --exclude "*abc_def*"
Step 2 It will Fetche latest abc file from Folder_Test2:
aws s3 ls s3://$bucket/Folder_Test2/ --recursive | sort | tail -n 1 | awk '{print $4}'
How can I copy the latest file from Folder_Test2 to Folder_Test3? or How can I remove all other files except the latest file from Folder_Test2?