Mon Sep 27 2021·2 min read
Photo by Joshua Earle
In order to exclude multiple folders when using S3
sync, pass multiple
--exclude parameters to the command, specifying the path to the folders you
want to exclude.
aws s3 sync s3://YOUR_BUCKET . --exclude "my-folder-1/*" --exclude "my-folder-2/*" --exclude "my-folder-3/*"
In the example above we've used the
exclude parameter to filter out 3 folders
from the sync command.
Because we've passed the root of the bucket after the
sync keyword in the
s3://my-bucket ), we have to specify the whole path for the
values of the
--excludeparameter must be in double quotes when issuing the command on
Let's look at an example where we have the following folder structure in the S3 bucket:
my-folder-1/ file1.txt file2.txt nested-folder-1/ nested-folder-2/
We want to exclude
nested-folder-2 from the sync command
and both of them are in the
my-folder-1 directory. Therefore we can add the
suffix to the bucket name, instead of repeating it in the value of all
aws s3 sync s3://YOUR_BUCKET/my-folder-1 . --exclude "nested-folder-1/*" --exclude "nested-folder-2/*"
In the example above we've specified the
my-folder-1 suffix to the bucket
name, which means that all of our
--exclude parameters start from that path.
--excludeparameter to filter out for specific files, including use wildcards.
The following example excludes all files with the
aws s3 sync s3://YOUR_BUCKET . --exclude "my-folder-1/*.png" --exclude "my-folder-1/*.pdf"
In the example above we've excluded all of the
my-folder-1 directory, however files with other extensions in the folder have
not been excluded, nor
I'll send you 1 email a week with links to all of the articles I've written that week