I have a number of files that are contained within subfolders of /myfolder
.
I would like to use aws cli to move them to /newfolder
.
For example:
/myfolder/2017_01_01/file1.txt
/myfolder/2017_01_02/file2.txt
...
I want to copy the files out to a new folder:
/newfolder/file1.txt
/newfolder/file2.txt
...
When I use the cp
command like below:
aws s3 cp s3://myfolder/ s3://newfolder/ --recursive --exclude '*' --include '*file*'
The correct files are copied, but the problem is that the files remain in their subfolders at the new location:
/newfolder/2017_01_01/file1.txt
/newfolder/2017_01_02/file2.txt
...
Is it possible to copy the files "out" of their subfolders so that they are directly put into /newfolder
?
s3://destination --recursive . That way, it is copying the contents of the current directory.
You can use cp to copy the files from an s3 bucket to your local system. Use the following command: $ aws s3 cp s3://bucket/folder/file.txt . To know more about AWS S3 and its features in detail check this out!
(Recommended) Upload the file using high-level (aws s3) commands. This example uses the command aws s3 cp, but other aws s3 commands that involve uploading objects into an S3 bucket (for example, aws s3 sync or aws s3 mv) also automatically perform a multipart upload when the object is large.
The easiest way to do this is a hybrid solution assuming you have linux shell: (make sure you create blank folder in your local computer and cd to it before doing the below steps)
1.aws s3 cp s3://yourBucket/myfolder . --recursive --include "*.txt"
2.find . -name '*txt' -exec mv {} . \;
3.aws s3 cp ./ s3://yourBucket/newfolder --exclude "*" --include "*.txt" --recursive
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With