https://wangyan.org/blog/s3cmd-how-to-use.html

s3cmd 安装使用指南

s3cmd 是一款 Amazon S3 命令行工具。它不仅能上传、下载、同步,还能设置权限,下面是完整的安装使用指南。

一、安装方法

方法一:(Debian/Ubuntu )

1
2
3
wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add -
wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list
apt-get update && sudo apt-get install s3cmd

方法二:

1
2
3
4
wget http://nchc.dl.sourceforge.net/project/s3tools/s3cmd/1.0.0/s3cmd-1.0.0.tar.gz
tar -zxf s3cmd-1.0.0.tar.gz -C /usr/local/
mv /usr/local/s3cmd-1.0.0/ /usr/local/s3cmd/
ln -s /usr/local/s3cmd/s3cmd /usr/bin/s3cmd

二、使用方法

1、配置,主要是 Access Key ID 和 Secret Access Key

1
s3cmd --configure

2、列举所有 Buckets。(bucket 相当于根文件夹)

1
s3cmd ls

3、创建 bucket,且 bucket 名称是唯一的,不能重复。

1
s3cmd mb s3://my-bucket-name

4、删除空 bucket

1
s3cmd rb s3://my-bucket-name

5、列举 Bucket 中的内容

1
s3cmd ls s3://my-bucket-name

6、上传 file.txt 到某个 bucket,

1
s3cmd put file.txt s3://my-bucket-name/file.txt

7、上传并将权限设置为所有人可读

1
s3cmd put --acl-public file.txt s3://my-bucket-name/file.txt

8、批量上传文件

1
s3cmd put ./* s3://my-bucket-name/

9、下载文件

1
s3cmd get s3://my-bucket-name/file.txt file.txt

10、批量下载

1
s3cmd get s3://my-bucket-name/* ./

11、删除文件

1
s3cmd del s3://my-bucket-name/file.txt

12、来获得对应的bucket所占用的空间大小

1
s3cmd du -H s3://my-bucket-name

三、目录处理规则

以下命令都能将dir1 中的文件上传至my-bucket-name,但效果只截然不同的。

1)dir1 不带"/"斜杠,那么dir1会作为文件路径的一部分,相当于上传整个dir1目录,即类似 "cp -r dir1/"

1
2
~/demo$ s3cmd put -r dir1 s3://my-bucket-name/
dir1/file1-.txt -> s3://my-bucket-name/dir1/file1-.txt [ of ]

2)带"/"斜杠的 dir1,相当于上传dir1目录下的所有文件,即类似 "cp ./* "

1
2
~/demo$ s3cmd put -r dir1/ s3://my-bucket-name/
dir1/file1-.txt -> s3://my-bucket-name/file1-.txt [ of ]

四、同步方法

这是s3cmd 使用难点,但却是最实用的功能。官方使用说明见《s3cmd sync HowTo》

首先明确,同步操作是要进行MD5校验的,只有当文件不同时,才会被传输。

4.1、常规同步操作

1、同步当前目录下所有文件

1
s3cmd sync  ./  s3://my-bucket-name/

2、加 "--dry-run"参数后,仅列出需要同步的项目,不实际进行同步。

1
s3cmd sync  --dry-run ./  s3://my-bucket-name/

3、加 " --delete-removed"参数后,会删除本地不存在的文件。

1
s3cmd sync  --delete-removed ./  s3://my-bucket-name/

4、加 " --skip-existing"参数后,不进行MD5校验,直接跳过本地已存在的文件。

1
s3cmd sync  --skip-existing ./  s3://my-bucket-name/

4.2、高级同步操作

4.2.1、排除、包含规则(--exclude 、--include)

file1-1.txt被排除,file2-2.txt同样是txt格式却能被包含。

1
2
3
~/demo$ s3cmd sync --dry-run --exclude '*.txt' --include 'dir2/*' ./  s3://my-bucket-name/
exclude: dir1/file1-.txt
upload: ./dir2/file2-.txt -> s3://my-bucket-name/dir2/file2-.txt

4.2.2、从文件中载入排除或包含规则。(--exclude-from、--include-from)

1
s3cmd sync  --exclude-from pictures.exclude ./  s3://my-bucket-name/

pictures.exclude 文件内容

1
2
3
# Hey, comments are allowed here ;-)
*.jpg
*.gif

4.2.3、排除或包含规则支持正则表达式

1
--rexclude 、--rinclude、--rexclude-from、--rinclude-from

s3cmd 安装使用指南的更多相关文章

  1. [转载]SharePoint 2013测试环境安装配置指南

    软件版本 Windows Server 2012 标准版 SQL Server 2012 标准版 SharePoint Server 2013 企业版 Office Web Apps 2013 备注: ...

  2. centOS安装Mysql指南

    centOS安装Mysql指南 说明:使用操作系统centOS6.4 32位系统:mysql:mysql-5.7.10-linux-glibc2.5-i686.tar.gz; 一.准备 下载mysql ...

  3. Cadence OrCad Allegro SPB 16.6 下载及安装破解指南

    Cadence公司的电子设计自动化产品涵盖了电子设计的整个流程,包括系统级设计,功能验证,IC综合及布局布线,模拟.混合信号及射频IC设计,全定制集成电路设计,IC物理验证,PCB设计和硬件仿真建模等 ...

  4. 【转】服务器证书安装配置指南(Weblogic)

    服务器证书安装配置指南(Weblogic) 详情请点击: http://verisign.itrus.com.cn/html/fuwuyuzhichi/fuwuqizhengshuanzhuangpe ...

  5. 大数据应用日志采集之Scribe 安装配置指南

    大数据应用日志采集之Scribe 安装配置指南 大数据应用日志采集之Scribe 安装配置指南 1.概述 Scribe是Facebook开源的日志收集系统,在Facebook内部已经得到大量的应用.它 ...

  6. Ubuntu 14 安装MySQL指南

    ubuntu 14 安装MySQL指南安装MySQLsudo apt-get install mysql-server这个应该很简单了,而且我觉得大家在安装方面也没什么太大问题,所以也就不多说了,下面 ...

  7. 【转】Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置

    Syncthing – 数据同步利器---自己的网盘,详细安装配置指南,内网使用,发现服务器配置 原贴:https://www.cnblogs.com/jackadam/p/8568833.html ...

  8. 阿里巴巴Java编码规范插件安装使用指南

    编码规范插件安装使用指南 阿里技术公众号公布的<阿里巴巴Java开发规约>,瞬间引起全民代码规范的热潮,后又发布了PDF的终极版,大家踊跃留言,期待配套的静态扫描工具开放出来. 为了让开发 ...

  9. 高可用,完全分布式Hadoop集群HDFS和MapReduce安装配置指南

    原文:http://my.oschina.net/wstone/blog/365010#OSC_h3_13 (WJW)高可用,完全分布式Hadoop集群HDFS和MapReduce安装配置指南 [X] ...

随机推荐

  1. Geforce experience报错:something went wrong try restarting geforce

    右键计算机 ——>管理——> 服务和应用程序 ——>服务中

  2. C++程序设计练习(一)

    // 1. 在屏幕上输出内容 #include<iostream> using namespace std; int main(){ int i= 1; cout<<" ...

  3. 001-unity3d简介以及界面说明

    一.简介 学习路线1.C#.网络[http,socket]io2.GUI.NGUI.2DToolKit3.3D控制.物理引擎.角色控制4.粒子系统.音频等5.android.IOS开发基础6.sock ...

  4. Parzen-Window Density Estimation(PWDE)

    1.概率密度函数 在在数学中,连续型随机变量的概率密度函数(在不至于混淆时可以简称为密度函数)是一个描述这个随机变量的输出值,在某个确定的取值点附近的可能性的函数.而随机变量的取值落在某个区域之内的概 ...

  5. 从SignalTap II中获取“最真实”的仿真测试向量(ZZ)

         在实际工作中,经常会遇到这样的情况:在硬件调试中采用SignalTap II反复多次编译并最终捕获到问题的原因时,才会发现,原来这个问题是逻辑问题,是可以在仿真环境下发现并快速解决的.先前没 ...

  6. gitattributes手册

    gitattributes(5) Manual Page 1.gitattributes是什么? gitattributes用于定义每个路径的属性. 其语法是:pattern attr1 attr2 ...

  7. 转:C语言嵌入式系统编程之软件架构篇

    http://blog.csdn.net/ce123_zhouwei/article/details/6978672

  8. 计算机网络概述 传输层 TCP拥塞控制

    TCP拥塞控制 计算机网络中的带宽.交换结点中的缓存和处理机等,都是网络的资源.在某段时间,若对网络中某一资源的需求超过了该资源所能提供的可用部分,网络的性能就会变坏.这种情况就叫做拥塞. 拥塞控制就 ...

  9. 【HackerRank】Closest Numbers

    Sorting is often useful as the first step in many different tasks. The most common task is to make f ...

  10. AngularJs 的一则错误 [$INJECTOR:MODULERR]

    Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modu ...