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-1.txt -> s3://my-bucket-name/dir1/file1-1.txt [1 of 1] |
2)帶"/"斜杠的 dir1,相當于上傳dir1目錄下的所有文件,即類似 "cp ./* "
| 1 2 | ~/demo$ s3cmd put -r dir1/ s3://my-bucket-name/ dir1/file1-1.txt -> s3://my-bucket-name/file1-1.txt [1 of 1] |
四、同步方法
這是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-1.txt upload: ./dir2/file2-2.txt -> s3://my-bucket-name/dir2/file2-2.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 安装使用指南的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python简笔画大全_只用C++和Py
- 下一篇: ReenactGAN: Learning