The s3cmd command is a powerful tool for managing AWS S3. It not only supports downloading and uploading files but also offers features like directory creation.
The use cases for s3cmd are diverse. For example, when backing up local log files to S3, you can combine s3cmd with cron jobs to perform regular backups. If the retention period for log files is 365 days, you can use s3cmd to delete specific directories from S3.
Here, we introduce how to upload and download files using the s3cmd command.
Uploading Files
Uploading a Specific Directory
Upload the /mnt/aws/backup directory to S3.
awsok.com is the bucket name, and aws/folder serves as the directory path on S3.
The -r flag can also be written as --recursive, indicating that all files within the backup directory, including those in subdirectories, will be uploaded.
# s3cmd put --r /mnt/aws/backup s3://awsok.com/aws/folder
Uploading a Specific File
Upload the local index.html file to the aws/folder directory on S3.
# s3cmd put --r /mnt/aws/backup/index.html s3://awsok.com/aws/folder
By default, uploaded files are set to private. You can explicitly specify the private option using --acl-private.
To make files public, use the --acl-public option.
Downloading Files
Downloading a Specific Directory
Download all files from the folder directory to the local /tmp directory.
# s3cmd get -r s3://awsok.com/aws/folder /tmp
Downloading a Specific File
Download the index.html file from the folder directory to the local /tmp directory.
# s3cmd get s3://awsok.com/aws/folder/index.html /tmp
Deleting Files
Deleting a Specific Directory
Delete the folder directory from S3.
# s3cmd del -r s3://awsok.com/aws/folder
Deleting a Specific File
Delete the index.html file located in the aws/folder directory on S3.
# s3cmd del s3://awsok.com/aws/folder/index.html