You can do this by providing an --exclude
or --include
argument multiple times. But, you'll have to use --recursive
for this to work.
When there are multiple filters, remember that the order of the filter parameters is important. The rule is the filters that appear later in the command take precedence over filters that appear earlier in the command.
aws s3 rm s3://x.y.z/ --recursive --exclude "*" --include "purple.gif" --include "worksheet.xlsx"
Here, all files will be excluded from the command except for purple.gif and worksheet.xlsx.
If you're unsure, always try a --dryrun
first and inspect which files will be deleted.
Source: Use of Exclude and Include Filters
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…