![](http://aws-guide.work/wp-content/themes/cocoon-master/images/b-woman.png)
AWS CLIで
・S3上の複数のファイルを削除
できます!
サンプルコマンド
ここでは例として
・バケット「tmp12345/sub1」配下のファイル「sub*.txt」を削除
します。
※今回はファイル「sub_001.txt」と「sub_002.txt」が削除されます。
![削除対象となるのは「sub_001.txt」と「sub_002.txt」の2ファイル](https://aws-guide.work/wp-content/uploads/2024/04/aws_cli_s3_rm_files_001.png)
構文は以下です。
aws s3 rm s3://バケット名/フォルダ名/ --exclude "*" --include "削除したいファイル(ワイルドカードを使用)" --recursive --profile プロファイル名
実行例は以下です。
aws s3 rm s3://tmp12345/sub1/ --exclude "*" --include "sub*.txt" --recursive --profile develop
実行結果
S3上の複数のファイルを削除できました。
※ファイル「sub_001.txt」と「sub_002.txt」の2ファイルを削除できました。
![](https://aws-guide.work/wp-content/uploads/2024/04/aws_cli_s3_rm_files_003.png)
![](https://aws-guide.work/wp-content/uploads/2024/04/aws_cli_s3_rm_files_004.png)
参考①
オプション「dryrun」を使用すると、テスト実行となります。(実際に削除されたりしません)。
![テスト実行](https://aws-guide.work/wp-content/uploads/2024/04/aws_cli_s3_rm_files_002.png)
参考②
「aws s3 rm」の詳細は、公式サイトをご確認ください。