Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 405
Adz Avatar asked Dec 10 '22 13:12

Adz


1 Answers

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/*"
like image 104
franklinsijo Avatar answered Jan 04 '23 16:01

franklinsijo