问题描述
我有一个程序,成功地上传所有我需要的所有文件。我有新的文件每天,我需要上传。之后,我已经上传了文件,我不再需要他们,因此我并不指望它们同步。
I having a program that successfully uploads all of the files that I need. I have new files everyday that I need to upload. After I have uploaded the files I no longer need them and thus am not looking to sync them.
我很好奇,如果有一种方法来检查,如果给定的路径和文件名,如果使用s3cmd内S3的存在。
I am curious if there is a way to check if given a path and file name if that exists within S3 using the s3cmd.
推荐答案
您可以使用ls命令s3cmd知道,如果一个文件是present与否S3。
You can use the ls command in s3cmd to know if a file is present or not in S3.
猛砸code
path=$1
count=`s3cmd ls $path | wc -l`
if [[ $count -gt 0 ]]; then
echo "exist"
else
echo "do not exist"
fi
用法:./s3_exist.sh S3://foo/bar.txt
Usage: ./s3_exist.sh s3://foo/bar.txt
编辑:
由于cocoatomo指出的评论, s3cmd LS $ PATH
列出所有程序文件的起始 $ PATH
。一个更安全的方法是使用 s3cmd信息$ PATH
并检查退出code。
As cocoatomo pointed out in comments, s3cmd ls $path
lists all file that begins with $path
. A safer approach would be to use s3cmd info $path
and check the exit code.
新的bash code
New Bash code
path=$1
s3cmd info $path >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo "exist"
else
echo "do not exist"
fi
这篇关于检查文件是否在S3存储桶使用s3cmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!