[对象存储] MinIO 命令行客户端: mc
1 概述:MinIO 命令行客户端(mc)
-
MinIO 的命令行客户端中,最标准、功能最全的方式是使用
MinIO Client(mc)。此外,由于MinIO兼容S3 API,也可以用aws-cli或curl进行简单操作。 -
mc,系MinIO官方提供的专用工具,功能最强大
2 使用指南
2.1 安装 mc
- Linux (amd64)
亲测有效
wget https://dl.min.io/client/mc/release/linux-amd64/mc
chmod +x mc
sudo mv mc /usr/local/bin/
- macOS (Homebrew)
brew install minio/stable/mc
2.2 配置连接(添加 Alias)
这是最关键的一步,相当于在命令行里保存一个“连接配置”。
- 命令格式
mc alias set <ALIAS_NAME> <MINIO_URL> <ACCESS_KEY> <SECRET_KEY>
示例:连接本地 MinIO
mc alias set myminio http://127.0.0.1:9000 minioadmin minioadminpassword
//示例:连接带有 HTTPS 的远程服务器
mc alias set prod-minio https://minio.example.com AKIAIOSFODNN7EXAMPLE wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
2.3 常用 Shell 操作
查验连接状态 *
每次重开 shell 会话窗口、且准备使用
mc命令前,均建议执行此操作验证一下。
ash-4.4# mc admin info myminio
● 127.0.0.1:6100
Uptime: 40 minutes
Version: 2025-02-07T23:21:09Z
Network: 1/1 OK
Drives: 1/1 OK
Pool: 1
┌──────┬──────────────────────┬─────────────────────┬──────────────┐
│ Pool │ Drives Usage │ Erasure stripe size │ Erasure sets │
│ 1st │ 2.6% (total: 10 TiB) │ 1 │ 1 │
└──────┴──────────────────────┴─────────────────────┴──────────────┘
0 B Used, 1 Bucket, 0 Objects
1 drive online, 0 drives offline, EC:0
bucket 管理
- 列举 buckets
ash-4.4# mc ls myminio
[2026-07-25 15:59:36 CST] 0B data-warehouse/
ash-4.4# mc stat myminio/
Name : data-warehouse/
Type : folder
Name : lakehouse/
Type : folder
Name : my-bucket/
Type : folder
- 查看指定的 bucket(含: region 等信息)
ash-4.4# mc stat myminio/lakehouse
Name : lakehouse
Date : 2026-07-27 15:33:08 CST
Size : N/A
Type : folder
Properties:
Versioning: Un-versioned
Location: us-east-1
Anonymous: Disabled
ILM: Disabled
Usage:
Total size: 0 B
Objects count: 0
Versions count: 0
Object sizes histogram:
0 object(s) BETWEEN_1024B_AND_1_MB
0 object(s) BETWEEN_1024_B_AND_64_KB
0 object(s) BETWEEN_10_MB_AND_64_MB
0 object(s) BETWEEN_128_MB_AND_512_MB
0 object(s) BETWEEN_1_MB_AND_10_MB
0 object(s) BETWEEN_256_KB_AND_512_KB
0 object(s) BETWEEN_512_KB_AND_1_MB
0 object(s) BETWEEN_64_KB_AND_256_KB
0 object(s) BETWEEN_64_MB_AND_128_MB
0 object(s) GREATER_THAN_512_MB
0 object(s) LESS_THAN_1024_B
- 创建 bucket
ash-4.4# mc mb myminio/my-bucket
Bucket created successfully `myminio/my-bucket`.
ash-4.4# mc ls myminio
[2026-07-25 15:59:36 CST] 0B data-warehouse/
[2026-07-25 19:43:13 CST] 0B my-bucket/
- 删除 buket
mc rb <别名>/<桶名>
ash-4.4# mc rb myminio/my-bucket
或
ash-4.4# mc rb --force myminio/my-bucket
Removed `myminio/my-bucket` successfully.
ash-4.4# mc ls myminio
[2026-07-25 15:59:36 CST] 0B data-warehouse/
对象管理(目录、文件)
- 上传文件
ash-4.4# echo "hello world" >> ~/test.txt
ash-4.4# ls -la ~/test.txt
-rw------- 1 root root 12 Jul 25 19:54 /root/test.txt
ash-4.4# mc cp ~/test.txt myminio/my-bucket/
/root/test.txt: 12 B / 12 B ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 124 B/s 0s
ash-4.4# rm ~/test.txt
- 递归上传目录
ash-4.4# mkdir -p ~/test-dir/test-sub-dir/
ash-4.4# echo "hello" >> ~/test-dir/test-sub-dir/demo.txt
ash-4.4# ls -la /root/test-dir/test-sub-dir/
total 12
drwx------ 2 root root 4096 Jul 25 20:05 .
drwx------ 3 root root 4096 Jul 25 19:57 ..
-rw------- 1 root root 6 Jul 25 20:05 demo.txt
ash-4.4# mc cp ~/test-dir/ myminio/my-bucket/ --recursive
...ir/test-sub-dir/demo.txt: 6 B / 6 B ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 103 B/s 0s
//查看上传文件的情况
ash-4.4# mc ls myminio/my-bucket/
[2026-07-25 19:55:52 CST] 12B STANDARD test.txt
[2026-07-25 20:09:06 CST] 0B test-sub-dir/
ash-4.4# mc ls myminio/my-bucket/test-sub-dir/
[2026-07-25 20:05:47 CST] 6B STANDARD demo.txt
ash-4.4# mc ls -r myminio/my-bucket/
[2026-07-25 20:05:47 CST] 6B STANDARD test-sub-dir/demo.txt
[2026-07-25 19:55:52 CST] 12B STANDARD test.txt
- 查看指定桶/指定目录下的文件对象
ash-4.4# mc ls myminio/my-bucket/
[2026-07-25 19:55:52 CST] 12B STANDARD test.txt
[2026-07-25 20:09:06 CST] 0B test-sub-dir/
ash-4.4# mc ls myminio/my-bucket/test-sub-dir/
[2026-07-25 20:05:47 CST] 6B STANDARD demo.txt
ash-4.4# mc ls -r myminio/my-bucket/
[2026-07-25 20:05:47 CST] 6B STANDARD test-sub-dir/demo.txt
[2026-07-25 19:55:52 CST] 12B STANDARD test.txt
- 从指定桶的指定目录中下载文件对象
//上传(到 MinIO)
ash-4.4# mc cp test.txt myminio/my-bucket
...es/xxxx-xxxx-dc/test.txt: 12 B / 12 B ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 111 B/s 0s
//下载(到 本地磁盘)
ash-4.4# mc cp myminio/my-bucket/test.txt ./
...:6100/my-bucket/test.txt: 12 B / 12 B ┃▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓┃ 1.83 KiB/s 0s
ash-4.4# ls -la | grep -i test
-rwx--x--x+ 1 root root 12 Jul 25 20:15 test.txt
- 删除文件
//删除成功(文件对象存在时)
ash-4.4# mc rm myminio/my-bucket/test.txt
Removed `myminio/my-bucket/test.txt`.
ash-4.4# mc ls myminio/my-bucket/
[2026-07-25 20:12:23 CST] 0B test-sub-dir/
ash-4.4# mc ls -r myminio/my-bucket/
[2026-07-25 20:05:47 CST] 6B STANDARD test-sub-dir/demo.txt
//删除失败(文件对象不存在时)
ash-4.4# mc rm myminio/my-bucket/test.txt
mc: <ERROR> Failed to remove `myminio/my-bucket/test.txt`. Object does not exist
Y 推荐文献
X 参考文献
本文作者:
千千寰宇
本文链接: https://www.cnblogs.com/johnnyzen
关于博文:评论和私信会在第一时间回复,或直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
日常交流:大数据与软件开发-QQ交流群: 774386015 【入群二维码】参见左下角。您的支持、鼓励是博主技术写作的重要动力!
本文链接: https://www.cnblogs.com/johnnyzen
关于博文:评论和私信会在第一时间回复,或直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
日常交流:大数据与软件开发-QQ交流群: 774386015 【入群二维码】参见左下角。您的支持、鼓励是博主技术写作的重要动力!

浙公网安备 33010602011771号