What it is
The MinIO Client (mc) is a command-line tool for interacting with MinIO object storage and other S3-compatible object storage services, allowing you to manage buckets, objects, and perform various operations like uploading, downloading, and syncing.
Installation
Linux
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
sudo mv mc /usr/local/bin/
macOS
wget https://dl.min.io/client/mc/release/darwin-amd64/mc
chmod +x mc
sudo mv mc /usr/local/bin/
Windows
Download the appropriate mc.exe from the MinIO releases page and place it in your system’s PATH.
Core Concepts
- Aliases:
mcuses aliases to represent configured MinIO or S3 endpoints. You define an alias once, and then refer to it by its alias name (e.g.,myS3,minio-prod). This simplifies commands by avoiding the need to repeatedly type endpoint URLs, access keys, and secret keys. - Buckets: Similar to directories in a file system, buckets are containers for objects in object storage.
- Objects: These are the actual data files stored within buckets. Objects have a key (their name/path within the bucket) and associated metadata.
Commands / Usage
Configuration and Aliases
-
Alias a new MinIO or S3 endpoint:
mc alias set myS3 http://192.168.1.100:9000 minioadmin minioadminSets up an alias named
myS3for a MinIO server athttp://192.168.1.100:9000usingminioadminas both access and secret key. -
List configured aliases:
mc alias listDisplays all currently configured aliases and their associated endpoints.
-
Remove an alias:
mc alias remove myS3Deletes the alias
myS3from your configuration.
Bucket Operations
-
Create a bucket:
mc mb myS3/my-new-bucketCreates a new bucket named
my-new-bucketon the MinIO instance aliased asmyS3. -
List buckets:
mc ls myS3Lists all buckets within the MinIO instance aliased as
myS3. -
Remove a bucket (must be empty):
mc rb myS3/my-old-bucketRemoves the bucket
my-old-bucketfrom themyS3instance. This command will fail if the bucket is not empty. -
Remove a bucket and its contents recursively:
mc rb --recursive myS3/my-old-bucketForcefully removes the bucket
my-old-bucketand all objects within it from themyS3instance. Use with caution.
Object Operations
-
List objects in a bucket:
mc ls myS3/my-bucketLists all objects and subdirectories within the
my-bucketon themyS3instance. -
List objects in a bucket with size and date:
mc ls --human-readable myS3/my-bucketLists objects with human-readable sizes and modification dates.
-
Upload a local file to a bucket:
mc cp /path/to/local/file.txt myS3/my-bucket/Copies
file.txtfrom your local filesystem to the root ofmy-bucketonmyS3. -
Upload a local file with a different name in the bucket:
mc cp /path/to/local/document.pdf myS3/my-bucket/new_document_name.pdfUploads
document.pdfand renames it tonew_document_name.pdfinmy-bucket. -
Upload a local directory recursively:
mc cp --recursive /path/to/local/folder myS3/my-bucket/Copies the entire
folderand its contents intomy-bucket. The folder itself will be created as a prefix if it doesn’t exist in the bucket. -
Download an object from a bucket:
mc cp myS3/my-bucket/remote_file.jpg /path/to/local/directory/Downloads
remote_file.jpgfrommyS3/my-bucket/to your local/path/to/local/directory/. -
Download an object and rename it locally:
mc cp myS3/my-bucket/remote_image.png /path/to/local/directory/local_image.pngDownloads
remote_image.pngand saves it aslocal_image.png. -
Download an entire bucket recursively:
mc cp --recursive myS3/my-bucket /path/to/local/destination/Downloads the entire
my-bucketand its contents to/path/to/local/destination/. -
Mirror a local directory to a bucket:
mc mirror /path/to/local/source/ myS3/my-bucket/Synchronizes the local
sourcedirectory withmyS3/my-bucket/. Only changed or new files will be uploaded. -
Mirror a bucket to a local directory:
mc mirror myS3/my-bucket/ /path/to/local/destination/Synchronizes
myS3/my-bucket/with the localdestinationdirectory. Only changed or new files will be downloaded. -
Remove an object:
mc rm myS3/my-bucket/file_to_delete.txtDeletes
file_to_delete.txtfrommyS3/my-bucket/. -
Remove multiple objects matching a pattern:
mc rm --recursive myS3/my-bucket/logs/2023/Recursively deletes all objects under the
logs/2023/prefix inmy-bucket. -
Move an object:
mc mv myS3/my-bucket/old_location/file.dat myS3/my-bucket/new_location/file.datMoves
file.datfromold_location/tonew_location/within the same bucket. -
Copy an object between buckets or MinIO instances:
mc cp myS3/my-bucket/source_file.dat myS3_backup/backup-bucket/source_file.datCopies
source_file.datfrommyS3/my-bucket/tomyS3_backup/backup-bucket/. -
Get object information (metadata):
mc stat myS3/my-bucket/my_object.txtDisplays detailed information about
my_object.txt, including ETag, size, content type, and last modified date. -
Presigned URL for temporary access:
mc share myS3/my-bucket/public_report.pdfGenerates a presigned URL to temporarily access
public_report.pdf. The default expiry is 7 days. -
Presigned URL with custom expiry:
mc share --expire 1h myS3/my-bucket/temporary_data.zipGenerates a presigned URL that is valid for 1 hour.
Sync Operations
-
Sync local directory to bucket:
mc sync /path/to/local/data myS3/my-bucket/data/Synchronizes the local
datadirectory with thedata/prefix inmyS3/my-bucket/. Only changed or new files are transferred. -
Sync bucket to local directory:
mc sync myS3/my-bucket/logs/ /path/to/local/logs/Synchronizes the
logs/prefix inmyS3/my-bucket/with the local/path/to/local/logs/directory.
Utility Commands
-
Get version information:
mc --versionDisplays the
mcclient version and build information. -
Display help for a command:
mc --help mc mb --helpShows general help or help for a specific subcommand.
Common Patterns
-
Download all objects from a bucket to a local directory:
mc cp --recursive myS3/my-bucket/* /local/download/path/This is a common way to bulk download. The
*acts as a wildcard to include all objects. -
Upload all
.logfiles from a local directory to a bucket:mc cp --recursive /local/logs/*.log myS3/my-bucket/logs/Uploads only files ending with
.logfrom the locallogsdirectory. -
Find and delete old log files in a bucket:
mc ls --recursive --json myS3/my-bucket/logs/ | jq -r '.[] | select(.Type == "Object" and (.Name | endswith(".log")) and (.LastModified | fromdateiso8601 < (now - (7 * 86400)))) | .Name' | xargs -I {} mc rm myS3/my-bucket/logs/{}This is a more advanced example using
jqto filter objects older than 7 days and then piping tomc rmto delete them. Requiresjqto be installed. -
Syncing a web server’s static assets to MinIO:
mc mirror /var/www/html/assets/ myS3/website-bucket/assets/Keeps the
assets/directory on MinIO in sync with the local web server’s assets. -
Backup a bucket to another MinIO instance:
mc mirror myS3/production-data/ myS3-backup/backup-data/Continuously mirrors data from one MinIO instance to another for backup purposes.
Gotchas
mc rbrequires an empty bucket by default: If you try to remove a non-empty bucket withmc rb, it will fail. Usemc rb --recursiveto force deletion of the bucket and its contents, but be extremely careful.- Path separators: MinIO and S3 use
/as the object path separator, even on Windows.mchandles this correctly, but be mindful when constructing paths. - Wildcards (
*) behavior: When used withmc cpormc rm, wildcards typically operate on the local filesystem or the remote object keys depending on the direction of the operation. For example,mc cp /local/dir/* remote/bucket/will copy files from/local/dir/intoremote/bucket/.mc cp remote/bucket/*.* /local/dir/will copy objects from the root ofremote/bucket/that match*.*to/local/dir/. mc mirrorvsmc sync:mirrorwill delete local files if they are not present in the remote destination (when syncing from remote to local) or remote objects if they are not present in the local source (when syncing from local to remote).syncis generally safer and only adds/updates files.- Permissions and Credentials: Ensure your MinIO client configuration (
mc alias set) uses the correct access and secret keys. Insufficient permissions will lead toAccess Deniederrors. - Large File Uploads: For very large files,
mcautomatically handles multipart uploads. However, network interruptions can cause partial uploads. Re-runningmc cpormc syncwill typically resume or re-upload only the necessary parts.