Amazon s3 s3cmd:基于扩展名搜索文件并从bucket中删除
我有一个S3存储桶,里面有数千个文件夹和许多txt文件 我想列出桶中的所有txt文件,以便检查它们是否可移动。如果是,请将其移除Amazon s3 s3cmd:基于扩展名搜索文件并从bucket中删除,amazon-s3,amazon-web-services,s3cmd,Amazon S3,Amazon Web Services,S3cmd,我有一个S3存储桶,里面有数千个文件夹和许多txt文件 我想列出桶中的所有txt文件,以便检查它们是否可移动。如果是,请将其移除 你知道如何使用s3cmd实现这一点吗?这相当简单,但取决于你希望检查的复杂程度。假设要删除文件名包含“foo”的每个文本文件: s3cmd --recursive ls s3://mybucket | awk '{ print $4 }' | grep "*.txt" | grep "foo" | xargs s3cmd del 如果您想要一个比grep更复
你知道如何使用s3cmd实现这一点吗?这相当简单,但取决于你希望检查的复杂程度。假设要删除文件名包含“foo”的每个文本文件:
s3cmd --recursive ls s3://mybucket |
awk '{ print $4 }' | grep "*.txt" | grep "foo" | xargs s3cmd del
如果您想要一个比grep更复杂的检查,只需将前三个命令重定向到一个文件,然后手动编辑该文件或使用或awk
或perl
或任何您喜欢的工具,然后cat
将输出转换为s3cmd
(根据检查情况,您也可以使用管道完成所有操作):
s3cmd --recursive ls s3://mybucket | awk '{ print $4 }' | grep "*.txt" > /tmp/textfiles
magic-command-to-check-filenames /tmp/textfiles
cat /tmp/textfiles | xargs s3cmd del