S3cmd
s3cmd --configure
S3没有文件夹的概念,只有桶(bucket)的概念。桶可以看做是一个namespace下 的根目录。
s3cmd mb s3://my-bucket-name
s3cmd rb s3://my-bucket-name
s3cmd ls
s3cmd ls s3://my-bucket-name
s3cmd put file.txt s3://my-bucket-name/file.txt
s3cmd put file.txt s3://my-bucket-name/
s3cmd put --acl-public file.txt s3://my-bucket-name/file.txt #上传并将权限设置为所有人可读
# 目录
s3cmd put ./* s3://my-bucket-name/ #批量上传文件
# 注意区分 dir1 和 dir1/ 的区别:与rsync的处理方式一致,dir1/等同于 dir1/*
# s3cmd put -r dir1 s3://my-bucket-name/
dir1/file1-1.txt -> s3://my-bucket-name/dir1/file1-1.txt [1 of 1]
# s3cmd put -r dir1/ s3://my-bucket-name/
dir1/file1-1.txt -> s3://my-bucket-name/file1-1.txt [1 of 1]
s3cmd get [-r] s3://BUCKET/OBJECT LOCAL_FILE
s3cmd del s3://BUCKET/OBJECT
s3cmd du [s3://BUCKET[/PREFIX]]
s3cmd du s3://my-bucket-name
s3cmd cp s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
s3cmd get s3://my-bucket-name/file.txt s3://my-bucket-copy-name2/file.txt
s3cmd mv s3://BUCKET1/OBJECT1 s3://BUCKET2[/OBJECT2]
s3cmd mv s3://my-bucket-name/file.txt s3://my-bucket-mv-name/file.txt
上传文件时指定权限public:
s3cmd put --acl-public file.txt s3://my-bucket-name/file.txt
为已上传的文件设置public权限
s3cmd setacl s3://BUCKET[/OBJECT] --acl-public|--acl-private
s3cmd setacl s3://my-bucket-name/myfile.txt --acl-public
生成url下载链接,并指定链接有效期
day=`date -d 'now + 1 year' +%s`
echo $day
# 生成文件url共享地址,并指定有效期,时间格式为时间戳
s3cmd signurl s3://my-bucket-name/file.txt $day
其他高级:https://www.cnblogs.com/zhyg6516/archive/2011/09/02/2163933.html
s3cmd sync LOCAL_DIR s3://BUCKET[/PREFIX]
s3cmd sync s3://BUCKET[/PREFIX] LOCAL_DIR
s3cmd sync s3://BUCKET[/PREFIX] s3://BUCKET[/PREFIX]
相关选项:
-p, --preserve
--check-md5 #默认值
--delete-removed
--skip-existing
示例:
#同步当前目录下所有文件
s3cmd sync ./ s3://my-bucket-name/
#加 "--dry-run"参数后,仅列出需要同步的项目,不实际进行同步。
s3cmd sync --dry-run ./ s3://my-bucket-name/
#加 " --delete-removed"参数后,会删除本地不存在的文件。
s3cmd sync --delete-removed ./ s3://my-bucket-name/
#加 " --skip-existing"参数后,不进行MD5校验,直接跳过本地已存在的文件。
s3cmd sync --skip-existing ./ s3://my-bucket-name/
- 排除、包含规则(–exclude=GLOB 、–include=GLOB)
#file1-1.txt被排除,file2-2.txt同样是txt格式却能被包含。
$ s3cmd sync --dry-run --exclude '*.txt' --include 'dir2/*' ./ s3://my-bucket-name/
exclude: dir1/file1-1.txt
upload: ./dir2/file2-2.txt -> s3://my-bucket-name/dir2/file2-2.txt
- 从文件中载入排除或包含规则。(–exclude-from=FILE-of-GLOB、–include-from=FILE-of-GLOB)
s3cmd sync --exclude-from pictures.exclude ./ s3://my-bucket-name/
pictures.exclude 文件内容:
# Hey, comments are allowed here ;-)
*.jpg
*.gif
- 排除或包含规则支持正则表达式
--rexclude=REGEXP 、--rinclude=REGEXP、--rexclude-from、--rinclude-from