使用ls和通配符检查s3中是否存在文件 [英] Check if file exists in s3 using ls and wildcard
问题描述
似乎很简单,但是语法不正确.我想知道使用通配符的文件在我的s3存储桶中是否存在.像
Seems so simple, but not getting the syntax right. I want to know if a file exists in my s3 bucket using wildcards. Something like
aws s3 ls s3://my-bucket/folder/*myfile*
目标是查看此存储桶中是否存在名为2016_myfile.txt
的文件或名为2011_myfile.csv
的文件.
The goal is to see if a file called 2016_myfile.txt
or a file called 2011_myfile.csv
exists within this bucket.
如果我运行命令,即使我知道该文件存在,它也不会返回任何内容.
If I run the command, it doesn't return anything even though I know this file exists there.
推荐答案
(从草稿中删除,因为这似乎回答了问题)
(re-drafted from comment as it appears this answered the question)
根据文档,目前不支持. 最简单(尽管效率最低)的解决方案是使用grep:
I myself tried, and failed to use wildcards in the aws-cli, and according to the docs, this is not currently supported. Simplest (though least efficient) solution would be to use grep:
aws s3 ls s3://my-bucket/folder/ | grep myfile
或者,您可以编写一个简短的python/other脚本来更有效地执行此操作(但不能在单个命令中完成)
Alternatively, you could write a short python/other script to do this more efficiently (but not in a single command)
这篇关于使用ls和通配符检查s3中是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!