Prasad
Prasad

Reputation: 333

AWS S3 - Example of searching files in S3 using regex

How to list the files in S3 using regex (in linux cli mode)? I have the files in s3 bucket like sales1.txt, sales2.txt etc. When I ran the below command nothing is displaying. Is there a command to list the all the files in S3 bucket with regex?

Command:

aws s3 ls s3://test/sales*txt

Expected output:

sales1.txt
sales2.txt
sales3.txt

Upvotes: 5

Views: 14208

Answers (3)

Vinodh
Vinodh

Reputation: 1

I have been trying to sort this, {aws s3 ls } command is not supporting any regex or pattern matching option. Wr have to use bash commands grep or awk.

aws s3 ls s3://bucket/path/ | grep sales|grep txt

aws s3 ls s3://bucket/path/ | grep sales..txt

Upvotes: 0

SeanO
SeanO

Reputation: 648

The accepted solution is too broad and matches too much. Try this:

aws s3 ls s3://test/ | grep sales.*\.txt

Upvotes: 0

Rez Moss
Rez Moss

Reputation: 4604

Use the following command

aws s3 ls s3://test/ | grep '[sales].txt'

Upvotes: 9

Related Questions