When you work with AWS S3 CLI and you run commands such as rm
, I strongly suggest using the --dryrun
flag:
--dryrun
(boolean) Displays the operations that would be performed using the specified command without actually running them.
For example, let’s say that we want to remove the file_1.txt
and file file_2.txt
from the my-bucket/myfolder
. Using the --dryrun
flag, will receive a message of which files would have been removed if we had actually run the command
aws s3 rm s3://my-bucket/myfolder/ --dryrun --recursive --exclude "*" --include "file_1.txt" --include "file_2.txt"
Output:
(dryrun) delete: 3://my-bucket/myfolder/file_1.txt (dryrun) delete: 3://my-bucket/myfolder/file_2.txt
NB: Keep in mind that the order of the filter options such as exclude
and include
plays a role. The filter options that appear later overwrite those that appear earlier. In our example, we excluded everything in the first place but then we included the two specific files. Since this can be tricky, before you run any kind of these commands, always use the --dryrun
flag!
Better safe than sorry!