-1

I have a **S3 bucket in which starting of every month ... will be added. And in the month lder daily **new files will be added .

0

You can define the current month directory on this way:

s3://project/js/Historical/$(date +%Y)/$(date +%b)

This will work if your locale is set to English and you have the name of the month with only 3 letters (first capital)!

To list the content use command:

aws s3 ls s3://project/js/Historical/$(date +%Y)/$(date +%b)

Here is your command:

aws s3 ls s3://project/js/Historical/$(date +%Y)/$(date +%b) | sort -rh | head -n 1 | awk {' print $2'}

If you want to have the full name of month do it on this way

aws s3 ls s3://project/js/Historical/$(date +%Y)/$(date +%m)_$(date +%B) | sort -rh | head -n 1 | awk {' print $2'}

If you have files creation for previous day you can use code like this:

aws s3 ls s3://project/js/Historical/$(date +%Y --date="1 day ago")/$(date +%m --date="1 day ago")_$(date +%B --date="1 day ago") | sort -rh | head -n 1 | awk {' print $2'}
  • Comments are not for extended discussion; this conversation has been moved to chat. – terdon Feb 18 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.