0

I have a bucket on aws and I wanna download top 100 of files inside the specified bucket. I can get one specific file using s3cmd likes the following:

s3cmd get s3://bucket_name/file_name.m4a

How to get 100 of them using a command? Is there any option for the get?

OmG
  • 18,337
  • 10
  • 57
  • 90
  • Which 100 are you looking for? 100 last modified? 100 by alphabetical order? – maafk Feb 24 '19 at 18:55
  • Why do you want to download the "top" 100 files? What are you doing with them? We might be able to offer a better solution if you provide more information. – John Rotenstein Feb 24 '19 at 19:57
  • @JohnRotenstein I just want 100 of them! not in uniform random, but 100 of them as a sample. – OmG Feb 25 '19 at 10:11
  • @tkwargs I just want 100 of them! not in uniform random, but 100 of them as a sample. – OmG Feb 25 '19 at 10:12
  • Side-note: These days, it is recommended to use the official [AWS Command-Line Interface (CLI)](http://aws.amazon.com/cli/) rather than `s3cmd`. – John Rotenstein Feb 25 '19 at 10:32
  • @JohnRotenstein Indeed, it's a customized s3 over a personal server. – OmG Feb 25 '19 at 10:38

1 Answers1

1

I don't know any solution for get option (it might exist). A solution which I found is:

s3cmd ls -r s3://bucket_name | grep -o 's3:.*' | head -n 100 | while read file; do s3cmd get $file; done

Something like this for rm can be found here.

OmG
  • 18,337
  • 10
  • 57
  • 90