Adz
Adz

Reputation: 2847

AWS S3 cli recursively moving files between folders in same directory?

I wanted to recursively move all file names matching "EU_GR" to EU/ folder

My folder structure before the query was run:

In /test/customers/
    EU_GR...csv
    EU_IT...csv
    old/
        |
        |
         ->     EU_GR...csv
                EU_GI...csv
    EU/ -> Folder I want to move files to (from old/ as well)

Command I ran

aws s3 mv s3://test/customers/ s3://test/customers/EU/ --recursive --exclude "*" --include "*EU_GR*"

This was what it produced, it move all these files to here, but it kept doing it recursively, and it wouldn't end. It created the folder EU/ multiple times (4 times), before I stopped it.

EU/EU/EU/EU/
          |
          |
           -> EU_GR...csv
              EU_GR...csv
              EU_GR...csv
              EU_GR...csv
              EU_GR...csv

Can someone explain to me what happened please? I only wanted to move the matching files up one folder. I'm guessing I messed up somewhere with the recursive and it kept looking at every folder (including EU/) and thus always matching with EU_GR?

Upvotes: 7

Views: 11677

Answers (1)

franklinsijo
franklinsijo

Reputation: 18270

The command is recursively moving the contents that are moved into s3://test/customers/EU/ also.

Try,

aws s3 mv s3://test/customers/ s3://test/customers/EU/ --recursive --exclude "*" --include "*EU_GR*" --exclude "*/EU/*"

Upvotes: 16

Related Questions