skip to Main Content

I’m on the newest AWS CLI version – 2.7.24

Trying to list all the files from all the folders I have (with a certain extension) on this path:

s3://myfiles/folders/

"folders" have this structure:

folder1
 - item
 - item
folder2
 - item
 - item
folder3
 - item
 - item

My aws cli command is:

aws s3 ls –recursive s3://myfiles/folders/ -> Which works fine. But when I add –include, it doesn’t work. Error: unknown options

Example:
aws s3 ls –recursive –exclude * –include "*.txt" s3://myfiles/folders/

Error: Unknown options: –exclude, , –include,*.txt

I did pip install -U awscli

I tried a lot of internet and stackoverflow stuff but nothing worked.

Any ideas?

3

Answers


  1. Chosen as BEST ANSWER

    Currently there is no such option as

    aws s3 ls --include
    

    or

    aws s3 ls --exclude
    

    There is an open feature request for that, but no solution so far.


  2. You can easily build the desired functionality by piping the result of the aws cli command to grep or similar.


    In Bash:

    Here’s an example which mirrors the "include" functionality:

    $ aws s3 ls s3://bucket --recursive | grep ".*.txt.*"
    

    Here’s an example which mirrors the "exclude" functionality:

    $ aws s3 ls s3://bucket --recursive | grep -v ".*.txt.*"
    

    In Powershell:

    Here’s an example which mirrors the "include" functionality:

    $ aws s3 ls s3://bucket --recursive | Select-String ".*.txt.*"
    

    Here’s an example which mirrors the "exclude" functionality:

    $ aws s3 ls s3://bucket --recursive | Select-String ".*.txt.*" -NotMatch
    
    Login or Signup to reply.
  3. You can do expansions with s3 ls if you want to match the beginning of the path…

    If I want to find all paths that start with a capital "C" inside a certain directory I can do this:

    aws s3 ls my-bucket/my-folder/C
    

    And it’ll match all folders that start with "C" inside my-bucket/my-folder/.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search