Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I copy all objects in root directory but not subdirectories with aws s3 cp?

I need to copy content inside a AWS S3 bucket root folder to another folder inside root.

I want copy all files in root (textfile1.txt etc) except other folders (folder1,folder2) in to the folder3.

What would be the aws s3 copy command for it?

/
folder1
folder2
textfile1.txt
textfile2.txt
--many other text files
folder3
like image 247
Harshana Avatar asked Jun 26 '17 05:06

Harshana


People also ask

Is it better to have multiple S3 buckets or one bucket with sub folders?

Simpler Permission with Multiple Buckets If the images are used in different use cases, using multiple buckets will simplify the permissions model, since you can give clients/users bucket level permissions instead of directory level permissions.

What is the command to copy files recursively in a folder to an S3 bucket?

When passed with the parameter --recursive the aws s3 cp command recursively copies all objects from source to destination. It can be used to download and upload large set of files from and to S3.

Can a user upload a whole folder and subfolders to the S3 bucket in a single click using S3 console?

To upload folders and files to an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.


1 Answers

This command will copy all files from the root of the bucket, but will not copy any sub-folders:

aws s3 cp s3://my-bucket s3://my-bucket/destination --recursive --exclude "*/*"
  • --recursive causes it to copy all files and folders
  • --exclude "*/*" prevents it from copying any objects with a / in the key (which is used to indicate a sub-folder)

See also:

  • Use of Exclude and Include Filters
  • aws s3 cp examples
like image 119
John Rotenstein Avatar answered Sep 22 '22 01:09

John Rotenstein