How to delete the files from AWS S3 except the recently 5 added updated files

0 votes

I could fetch the recent 5 files added or updated by:

aws s3 ls s3://somebucket/ --recursive | sort | tail -n 5 | awk '{print $4}'
Now how do I keep these files and delete all other?
Jul 30, 2018 in Cloud Computing by code_ninja
• 6,300 points
3,864 views

1 answer to this question.

0 votes
Use AWS s3 rm command with multiple --exclude options as shown:
aws s3 rm s3://somebucket/ --recursive --exclude "somebucket/1.txt" --exclude "somebucket/2.txt" --exclude "somebucket/3.txt" --exclude "somebucket/4.txt" --exclude "somebucket/5.txt"



answered Jul 30, 2018 by Gopalan
• 1,360 points

Related Questions In Cloud Computing

+4 votes
2 answers

How come AWS S3 is erasing my extension from PDF files?

I think the problem should be with ...READ MORE

answered Mar 27, 2018 in Cloud Computing by code_ninja
• 6,300 points
4,002 views
+4 votes
2 answers

Amazon S3 Permission problem - How to set permissions for all files at once?

This can be done by setting the ...READ MORE

answered Mar 27, 2018 in Cloud Computing by brat_1
• 7,200 points
4,067 views
+4 votes
5 answers

How to do parallel uploads to the same s3 bucket directory with s3cmd?

Is your problem is not with the ...READ MORE

answered Oct 11, 2018 in Cloud Computing by findingbugs
• 4,780 points
4,784 views
0 votes
1 answer

Is there a way to transfer files between AWS s3 and ec2

The answer is a definite yes yes. ...READ MORE

answered Apr 17, 2018 in Cloud Computing by brat_1
• 7,200 points
884 views
+1 vote
2 answers

AWS CloudWatch Logs in Docker

The awslogs works without using ECS. you need to configure ...READ MORE

answered Sep 7, 2018 in AWS by bug_seeker
• 15,510 points
2,032 views
0 votes
1 answer
+8 votes
3 answers

How to download folder from AWS S3?

To Download using AWS S3 CLI : aws ...READ MORE

answered Sep 7, 2018 in Cloud Computing by eatcodesleeprepeat
• 4,710 points
289,026 views
0 votes
1 answer

sync --delete command removed all local files in AWS S3

aws sync is not used for deleting ...READ MORE

answered Jul 18, 2018 in Cloud Computing by Gopalan
• 1,360 points
8,317 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP