Amazon s3cmd ls

Shreya picture Shreya · Sep 29, 2015 · Viewed 7.1k times · Source

I have a requirement to list the file from an Amazon S3 location:

BUCKET= "s3://static.abc.com"
s3cmd ls --recursive $BUCKET/colorpics/*/640/

The colorpics directory contains multiple sub-directories for years like:

2013
2014
2015
2016

So the ls command should list the images for all the years dynamically and it should list only from next level sub-directory /640/.

If I give /*/ it works when the file system is mounted. But when I try to list from the bucket it fails.

Is there anyway I can achieve it?

Answer

John Rotenstein picture John Rotenstein · Sep 30, 2015

The Amazon S3 API can return the content of a bucket based on a prefix such as s3://static.abc.com/colorpics/, however it cannot have a wildcard mid-pattern. This is probably why s3cmd cannot provide that functionality.

By the way, these days it is better to use the official AWS Command-Line Interface (CLI), which has a matching aws s3 ls command.