ArticleDirectory
- I. Installation Method
- Ii. Usage
- Iii. Directory processing rules
- Iv. Synchronization Method
Https://wangyan.org/blog/s3cmd-how-to-use.html
S3cmd Installation Guide
S3cmd is an Amazon S3 command line tool. It not only supports upload, download, and synchronization, but also allows you to set permissions. The following is a complete installation guide.
I. Installation Method
Method 1: (Debian/UBUNTU)
123 |
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 |
Method 2:
1234 |
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 |
Ii. Usage
1. configuration, mainly access key ID and secret access key
2. List all buckets. (Bucket is equivalent to the root folder)
3. Create a bucket. The bucket name must be unique and cannot be repeated.
1 |
S3cmd MB S3://My-bucket-name |
4. delete an empty bucket
1 |
S3cmd RB S3://My-bucket-name |
5. List bucket content
1 |
S3cmdLsS3://My-bucket-name |
6. Upload file.txt to a bucket,
1 |
S3cmd put file.txt S3://My-bucket-name/File.txt |
7. Upload and set the permission to be readable by all users
1 |
S3cmd put-- ACL-PublicFile.txt S3://My-bucket-name/File.txt |
8. upload files in batches
1 |
S3cmd put./*S3://My-bucket-name/ |
9. download files
1 |
S3cmd get S3://My-bucket-name/File.txt |
10. Batch download
1 |
S3cmd get S3://My-bucket-name/*./ |
11. delete an object
1 |
S3cmd del S3://My-bucket-name/File.txt |
12. To obtain the space occupied by the corresponding Bucket
1 |
S3cmdDu -HS3://My-bucket-name |
Iii. Directory processing rules
The following commands can upload files in dir1 to my-bucket-name, but the effect is only different.
1) dir1 does not contain a slash (/), so dir1 will be part of the file path, which is equivalent to uploading the entire dir1 directory, that is, similar to "CP-r dir1 /"
12 |
~ / 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 with a slash (/) is equivalent to uploading all files under the dir1 directory, that is, similar to "CP./*"
12 |
~ / demo $ s3cmd put -r dir1 / S3: // my-bucket-name / dir1 / file1- 1 . TXT-> S3: /// my-bucket-name / file1- 1 . TXT [ 1 of 1 ] |
Iv. Synchronization Method
This is the most practical feature of s3cmd. For official instructions, see s3cmd sync howto
First, it is clear that the synchronization operation requires MD5 verification and will be transmitted only when the files are different.
4.1 General synchronization operations
1. Synchronize all files in the current directory
1 |
S3cmdSync./S3://My-bucket-name/ |
2. After the "-- dry-Run" parameter is added, only the items to be synchronized are listed and not actually synchronized.
1 |
S3cmdSync-- Dry-run./S3://My-bucket-name/ |
3. After the "-- delete-removed" parameter is added, files that do not exist locally are deleted.
1 |
S3cmdSync-- Delete-removed./S3://My-bucket-name/ |
4. After the "-- skip-existing" parameter is added, the existing local files are skipped without MD5 verification.
1 |
S3cmdSync-- Skip-existing./S3://My-bucket-name/ |
4.2 advanced synchronization operations
4.2.1 exclude and include rules (-- exclude, -- include)
When file1-1.txtis excluded, file2-2.txt is also included in the TXT format.
123 |
~ / Demo $ s3cmd Sync -- Dry-run -- Exclude '*. Txt' -- Include 'Dir2 /*' . / S3: // My-bucket-name / Exclude: dir1 / File1- 1 . Txtupload :. / Dir2 / File2- 2 . Txt-> S3: // My-bucket-name / Dir2 / File2- 2 . Txt |
4.2.2 load exclusion or inclusion rules from files. (-- Exclude-from, -- include-from)
1 |
S3cmdSync-- Exclude-fromPictures. exclude./S3://My-bucket-name/ |
Pictures. exclude file content
123 |
# Hey, comments are allowed here*. Jpg*. Gif |
4.2.3 Regular Expressions supported for exclusion or inclusion rules
1 |
-- Rexclude, -- Rinclude, -- rexclude-from, -- rinclude-from |