LinuxCommandLibrary

s3cmd

Manage files on Amazon S3

TLDR

Invoke configuration/reconfiguration tool

$ s3cmd --configure
copy

List Buckets/Folders/Objects
$ s3cmd ls s3://[bucket|path/to/file]
copy

Create Bucket/Folder
$ s3cmd mb s3://[bucket]
copy

Download a specific file from a bucket
$ s3cmd get s3://[bucket_name]/[path/to/file] [path/to/local_file]
copy

Upload a file to a bucket
$ s3cmd put [local_file] s3://[bucket]/[file]
copy

Move an object to a specific bucket location
$ s3cmd mv s3://[src_bucket]/[src_object] s3://[dst_bucket]/[dst_object]
copy

Delete a specific object
$ s3cmd rm s3://[bucket]/[object]
copy

SYNOPSIS

s3cmd [OPTIONS] COMMAND [ARGS]

Common commands include:
  s3cmd ls [s3://BUCKET[/PREFIX]]
  s3cmd put FILE [FILE...] s3://BUCKET[/PREFIX]
  s3cmd get s3://BUCKET/OBJECT [LOCAL_FILE]
  s3cmd sync LOCAL_DIR s3://BUCKET[/PREFIX]
  s3cmd mb s3://BUCKET
  s3cmd rb s3://BUCKET

PARAMETERS

--configure
    Launches an interactive wizard to set up access keys and other configuration options for S3 access.

--force
    Performs the action without asking for confirmation, useful for scripting.

--dry-run
    Simulates the command execution and displays what actions would be taken without actually performing them.

-r, --recursive
    Applies the command recursively to all files and subdirectories within a specified path.

--acl-public
    Sets the Access Control List (ACL) of uploaded objects to public-read, making them accessible to anyone via their URL.

--delete-removed
    (Used with sync) Deletes files in the destination S3 bucket that do not exist in the source directory.

--encrypt
    Encrypts uploaded objects on the S3 server side using S3-managed encryption keys (SSE-S3).

--add-header=HEADER:VALUE
    Adds a custom HTTP header to the S3 request, useful for setting metadata or specific S3 options.

DESCRIPTION

s3cmd is a powerful command-line tool designed for interacting with Amazon Simple Storage Service (S3) and other S3-compatible object storage solutions, such as Google Cloud Storage, Ceph, and MinIO. It provides a comprehensive set of functionalities to manage data stored in the cloud. Users can perform essential operations like uploading files and entire directories, downloading objects, synchronizing local directories with S3 buckets, listing bucket contents, creating and deleting buckets, and managing object permissions (ACLs). s3cmd supports advanced features like multipart uploads for large files, encryption, and the ability to configure multiple profiles for different storage accounts. Its intuitive syntax and robust capabilities make it an excellent choice for scripting automated backups, data transfers, and general cloud storage administration tasks directly from the Linux command line. It's widely used by developers and system administrators for efficient data management in cloud environments.

CAVEATS

s3cmd relies heavily on its configuration file (typically ~/.s3cfg) for authentication credentials and default settings; incorrect or missing configuration will prevent operation. While functional, it might not support the very latest S3 features or regional nuances as quickly as AWS's official command-line tools. For large-scale operations or complex S3 features (e.g., advanced Glacier operations, S3 Select), the official AWS CLI might offer more comprehensive support and performance.

CONFIGURATION

s3cmd requires a configuration file, typically located at ~/.s3cfg. This file stores your AWS Access Key ID, Secret Access Key, and other default settings. It can be easily generated or modified using the s3cmd --configure command, which guides you through the setup process. Proper configuration is essential for s3cmd to authenticate and interact with your S3 buckets.

S3 CONCEPTS: BUCKETS AND OBJECTS

Amazon S3 operates on two primary concepts: buckets and objects. A bucket is a container for objects, similar to a top-level directory. It must have a globally unique name. An object is the fundamental entity stored in S3, consisting of data (e.g., a file) and its metadata. s3cmd allows you to manage both, creating/delleting buckets and uploading/downloading/manipulating objects within them.

HISTORY

s3cmd originated as an open-source project written in Python, designed to provide a simple command-line interface for Amazon S3. It gained popularity as one of the earliest and most widely used non-official tools for S3 interaction, preceding the development of the official AWS CLI. Over the years, it has been maintained by a community of developers, adapting to changes in the S3 API and remaining a popular choice for straightforward S3 operations and scripting.

SEE ALSO

aws(1), mc(1), rsync(1)

Copied to clipboard