This post will helps you to find in the Last one hour files or directories and copy those files/directories from AW S3 bucket to in your Local machine or AWS EC2 instance using the Shell script,

Before, you execute the shell script make sure that are you able to access the AWS S3 buckets from your location where do you want to save the files. And Install an AWS CLI package in your machine.

Create a new file named:

DATE=`date "+%Y-%m-%d"` 
HOUR_NOW=`date "+%H"` 
HOUR=`expr $HOUR_NOW - 1` 
FILENAME=($(aws s3 ls s3://"$BUCKET_NAME"/ --recursive | sort | grep "$DATE" | grep "$HOUR:" | awk '{print $4}' ) ) 

for FILE in "${FILENAME[@]}" 
  sleep 2s 
  aws s3 cp s3://"$BUCKET_NAME"/$FILE /your_destination/  --recursive

Give the writable permission using the command below,
chmod +x
chmod 755

Finally, execute the script with the command below,