- 1 year ago
In this AWS CLI command, why copying files with --exclude & --include wildcards not working?
If the AWS CLI command with --exclude
and --include
wildcards is not working as expected when copying files, there are a few potential reasons:
Incorrect Wildcard Syntax: Make sure you are using the correct wildcard syntax for the
--exclude
and--include
options. The AWS CLI uses the S3-specific wildcard syntax, which supports the use of*
for matching any number of characters and?
for matching a single character. Additionally, you can use the[]
notation for specifying character ranges. Verify that your wildcard patterns are properly formatted and match the desired files.Order of Options: Ensure that the
--exclude
and--include
options are placed in the correct order in the command. The AWS CLI evaluates the patterns in the order they are specified. If an--exclude
pattern matches a file before an--include
pattern, the file will be excluded regardless of any subsequent--include
patterns.For example, consider the following command:
bashaws s3 cp source/ s3://bucket/ --exclude "*.txt" --include "important.txt"
In this case, the
--exclude
pattern"*.txt"
will match all files with the.txt
extension, excluding them from the copy operation. The--include
pattern"important.txt"
will have no effect because the file has already been excluded.To resolve this, ensure that the
--include
patterns are specified before the--exclude
patterns, so that the desired files are included before any exclusions are applied.File Paths: Double-check the paths of the files you are trying to copy. The
--exclude
and--include
options evaluate patterns against file paths relative to the source directory. If the file paths do not match the patterns, they will not be included or excluded correctly.Case Sensitivity: Consider the case sensitivity of the patterns and file paths. The AWS CLI's wildcard matching is case-sensitive by default. Ensure that your patterns and file paths match in terms of case. If the patterns or file paths have different cases, the matching may not occur as expected.
If you've reviewed these aspects and the --exclude
and --include
options still do not work as intended, it may be helpful to provide the specific command you are using and any error messages or unexpected behavior you are experiencing for further assistance.