> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bitiful.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bitiful.com/_mcp/server.

# 使用 MinIO CLI（mc）

> 用 MinIO Client（mc）连接缤纷云 S4：配置别名、上传下载、同步与监听目录、查找、分享链接和标签。

MinIO Client（`mc`）是命令行工具，用法接近 Unix 的 `ls`、`cp`、`find`，可以连接任何兼容 S3 的对象存储。

> **Warning**
>
> MinIO 已停止维护 `mc`，官方网站不再提供下载，也不再发布安全更新。已经在用的可以继续，本文的命令在最后一个版本上实测可用。新项目建议用 [AWS CLI、s5cmd](https://docs.bitiful.com/clients/aws-cli.md) 或 [Rclone](https://docs.bitiful.com/clients/rclone.md)。

## 前置条件

- 已 [创建存储桶](https://docs.bitiful.com/bitiful-s4/handbook/buckets.md)；
- 已 [创建子账户与 AccessKey](https://docs.bitiful.com/bitiful-s4/handbook/access-keys.md)，并完成 [授权](https://docs.bitiful.com/bitiful-s4/handbook/permissions.md)。

## 安装

**Windows**

先安装 [Go](https://go.dev/dl/)，再执行：

```powershell title="PowerShell"
go install github.com/minio/mc@latest
```

**macOS**

```bash
brew install minio-mc
```

**Linux**

先安装 [Go](https://go.dev/dl/)，再执行：

```bash
go install github.com/minio/mc@latest
```

Windows 的命令请在 PowerShell 里运行，示例里的 `D:\` 换成自己的目录。

Homebrew 已把它标记为弃用，计划在 2027 年 7 月停用。社区维护的分支见 [pgsty/mc](https://github.com/pgsty/mc)，程序名为 `mcli`，命令相同。

Linux 上如果装过 Midnight Commander，它的程序也叫 `mc`，请给其中一个改名。

## 配置

**Windows**

```powershell title="PowerShell"
mc.exe alias set s4 https://s3.bitiful.net "你的 AccessKey" "你的 SecretKey" --api S3v4
```

**macOS**

```bash
mc alias set s4 https://s3.bitiful.net "你的 AccessKey" "你的 SecretKey" --api S3v4
```

**Linux**

```bash
mc alias set s4 https://s3.bitiful.net "你的 AccessKey" "你的 SecretKey" --api S3v4
```

之后用 `s4/桶名/路径` 表示 S4 上的位置。验证：

**Windows**

```powershell title="PowerShell"
mc.exe ls s4
mc.exe ls s4/my-bucket/
```

**macOS**

```bash
mc ls s4
mc ls s4/my-bucket/
```

**Linux**

```bash
mc ls s4
mc ls s4/my-bucket/
```

密钥保存在 `~/.mc/config.json`（Windows 为 `C:\Users\用户名\mc\config.json`），没有加密，注意文件权限。

## 上传与下载

**Windows**

```powershell title="PowerShell"
# 上传文件、目录
mc.exe cp D:\logo.png s4/my-bucket/images/logo.png
mc.exe cp -r D:\dist\ s4/my-bucket/site/

# 指定类型、缓存和自定义元数据，用分号分隔
mc.exe cp --attr "Cache-Control=max-age=86400;Content-Type=text/css;owner=web" D:\app.css s4/my-bucket/static/app.css

# 备份数据库并上传
mysqldump.exe mydb --result-file=D:\backup\mydb.sql
mc.exe cp D:\backup\mydb.sql s4/my-bucket/backup/mydb.sql

# 下载
mc.exe cp s4/my-bucket/images/logo.png D:\
mc.exe get s4/my-bucket/images/logo.png D:\logo.png
```

**macOS**

```bash
# 上传文件、目录
mc cp ./logo.png s4/my-bucket/images/logo.png
mc cp -r ./dist/ s4/my-bucket/site/

# 指定类型、缓存和自定义元数据，用分号分隔
mc cp --attr "Cache-Control=max-age=86400;Content-Type=text/css;owner=web" ./app.css s4/my-bucket/static/app.css

# 从标准输入上传
mysqldump mydb | gzip | mc pipe s4/my-bucket/backup/mydb.sql.gz

# 下载
mc cp s4/my-bucket/images/logo.png ./
mc get s4/my-bucket/images/logo.png ./logo.png
```

**Linux**

```bash
# 上传文件、目录
mc cp ./logo.png s4/my-bucket/images/logo.png
mc cp -r ./dist/ s4/my-bucket/site/

# 指定类型、缓存和自定义元数据，用分号分隔
mc cp --attr "Cache-Control=max-age=86400;Content-Type=text/css;owner=web" ./app.css s4/my-bucket/static/app.css

# 从标准输入上传
mysqldump mydb | gzip | mc pipe s4/my-bucket/backup/mydb.sql.gz

# 下载
mc cp s4/my-bucket/images/logo.png ./
mc get s4/my-bucket/images/logo.png ./logo.png
```

大文件自动分片上传。

## 同步目录

**Windows**

```powershell title="PowerShell"
# 先预演
mc.exe mirror --dry-run --overwrite --remove D:\dist s4/my-bucket/site

# 让目标与本地一致，--remove 会删除目标里多余的文件
mc.exe mirror --overwrite --remove D:\dist s4/my-bucket/site

# 下载整个目录
mc.exe mirror s4/my-bucket/site D:\site

# 持续监听本地目录，有变化就上传
mc.exe mirror --watch D:\uploads s4/my-bucket/uploads
```

**macOS**

```bash
# 先预演
mc mirror --dry-run --overwrite --remove ./dist s4/my-bucket/site

# 让目标与本地一致，--remove 会删除目标里多余的文件
mc mirror --overwrite --remove ./dist s4/my-bucket/site

# 下载整个目录
mc mirror s4/my-bucket/site ./site

# 持续监听本地目录，有变化就上传
mc mirror --watch ./uploads s4/my-bucket/uploads
```

**Linux**

```bash
# 先预演
mc mirror --dry-run --overwrite --remove ./dist s4/my-bucket/site

# 让目标与本地一致，--remove 会删除目标里多余的文件
mc mirror --overwrite --remove ./dist s4/my-bucket/site

# 下载整个目录
mc mirror s4/my-bucket/site ./site

# 持续监听本地目录，有变化就上传
mc mirror --watch ./uploads s4/my-bucket/uploads
```

> **Warning**
>
> `--remove` 会删除目标中源没有的文件，S4 没有回收站，请先用 `--dry-run` 预演。

## 查看与查找

**Windows**

```powershell title="PowerShell"
mc.exe ls -r s4/my-bucket/images/                                # 递归列出
mc.exe du s4/my-bucket/images                                    # 统计容量
mc.exe stat s4/my-bucket/images/logo.png                         # 元数据
mc.exe cat s4/my-bucket/notes/todo.txt                           # 查看内容
mc.exe head -n 20 s4/my-bucket/logs/app.log                      # 前 20 行
mc.exe diff D:\dist s4/my-bucket/site                            # 比较本地与桶

mc.exe find s4/my-bucket --name "*.mp4"                          # 按名称
mc.exe find s4/my-bucket --older-than 30d --larger 100MB         # 按时间和大小
```

**macOS**

```bash
mc ls -r s4/my-bucket/images/                                # 递归列出
mc du s4/my-bucket/images                                    # 统计容量
mc stat s4/my-bucket/images/logo.png                         # 元数据
mc cat s4/my-bucket/notes/todo.txt                           # 查看内容
mc head -n 20 s4/my-bucket/logs/app.log                      # 前 20 行
mc diff ./dist s4/my-bucket/site                             # 比较本地与桶

mc find s4/my-bucket --name "*.mp4"                          # 按名称
mc find s4/my-bucket --older-than 30d --larger 100MB         # 按时间和大小
```

**Linux**

```bash
mc ls -r s4/my-bucket/images/                                # 递归列出
mc du s4/my-bucket/images                                    # 统计容量
mc stat s4/my-bucket/images/logo.png                         # 元数据
mc cat s4/my-bucket/notes/todo.txt                           # 查看内容
mc head -n 20 s4/my-bucket/logs/app.log                      # 前 20 行
mc diff ./dist s4/my-bucket/site                             # 比较本地与桶

mc find s4/my-bucket --name "*.mp4"                          # 按名称
mc find s4/my-bucket --older-than 30d --larger 100MB         # 按时间和大小
```

## 移动与删除

**Windows**

```powershell title="PowerShell"
mc.exe mv s4/my-bucket/a.txt s4/my-bucket/b.txt

mc.exe rm s4/my-bucket/a.txt
mc.exe rm -r --force s4/my-bucket/tmp/                           # 删除整个目录，无法恢复
mc.exe rm -r --force --older-than 30d s4/my-bucket/logs/         # 只删 30 天前的
```

**macOS**

```bash
mc mv s4/my-bucket/a.txt s4/my-bucket/b.txt

mc rm s4/my-bucket/a.txt
mc rm -r --force s4/my-bucket/tmp/                           # 删除整个目录，无法恢复
mc rm -r --force --older-than 30d s4/my-bucket/logs/         # 只删 30 天前的
```

**Linux**

```bash
mc mv s4/my-bucket/a.txt s4/my-bucket/b.txt

mc rm s4/my-bucket/a.txt
mc rm -r --force s4/my-bucket/tmp/                           # 删除整个目录，无法恢复
mc rm -r --force --older-than 30d s4/my-bucket/logs/         # 只删 30 天前的
```

`mc mv` 会先复制再删除。大文件请用 S4 的 [原生移动](https://docs.bitiful.com/bitiful-s4/features/move-object.md)。

## 分享链接

**Windows**

```powershell title="PowerShell"
mc.exe share download --expire 1h s4/my-bucket/images/logo.png
```

**macOS**

```bash
mc share download --expire 1h s4/my-bucket/images/logo.png
```

**Linux**

```bash
mc share download --expire 1h s4/my-bucket/images/logo.png
```

有效期最长 7 天（`168h`）。

## 标签

**Windows**

```powershell title="PowerShell"
mc.exe tag set s4/my-bucket/images/logo.png "env=prod&team=web"
mc.exe tag list s4/my-bucket/images/logo.png
```

**macOS**

```bash
mc tag set s4/my-bucket/images/logo.png "env=prod&team=web"
mc tag list s4/my-bucket/images/logo.png
```

**Linux**

```bash
mc tag set s4/my-bucket/images/logo.png "env=prod&team=web"
mc tag list s4/my-bucket/images/logo.png
```

## 未完成的分片上传

**Windows**

```powershell title="PowerShell"
mc.exe ls --incomplete s4/my-bucket/
mc.exe rm -r --force --incomplete s4/my-bucket/
```

**macOS**

```bash
mc ls --incomplete s4/my-bucket/
mc rm -r --force --incomplete s4/my-bucket/
```

**Linux**

```bash
mc ls --incomplete s4/my-bucket/
mc rm -r --force --incomplete s4/my-bucket/
```

## 在两个存储之间复制

给其他存储也设置一个别名，就可以直接复制：

**Windows**

```powershell title="PowerShell"
mc.exe alias set old https://oss-cn-hangzhou.aliyuncs.com "源的 AccessKey" "源的 SecretKey"
mc.exe mirror old/old-bucket s4/my-bucket
```

**macOS**

```bash
mc alias set old https://oss-cn-hangzhou.aliyuncs.com "源的 AccessKey" "源的 SecretKey"
mc mirror old/old-bucket s4/my-bucket
```

**Linux**

```bash
mc alias set old https://oss-cn-hangzhou.aliyuncs.com "源的 AccessKey" "源的 SecretKey"
mc mirror old/old-bucket s4/my-bucket
```

数据会经过运行 mc 的机器。

## 不适用的命令

`mc admin`、`mc anonymous set`、`mc ilm`、`mc replicate`、`mc version enable`、`mc encrypt` 等用于管理 MinIO 服务端，或依赖 S4 没有提供的功能。对应的设置请在控制台操作：

| 需求     | 在控制台的位置                                                               |
| ------ | --------------------------------------------------------------------- |
| 公开读取   | [公共读与私有](https://docs.bitiful.com/bitiful-s4/handbook/public-read.md) |
| 子账户与授权 | [子账户权限](https://docs.bitiful.com/bitiful-s4/handbook/permissions.md)  |
| 跨域     | [跨域设置 CORS](https://docs.bitiful.com/bitiful-s4/handbook/cors.md)     |

子账户不能创建桶，`mc mb` 会返回权限错误。

## 常见问题

<details>
<summary>The request signature we calculated does not match</summary>

检查密钥是否多了空格、本机时间是否准确。密钥含特殊字符时要加引号。

</details>

<details>
<summary>mc ls s4 是空的</summary>

只会列出子账户有授权的桶，请先 [授权](https://docs.bitiful.com/bitiful-s4/handbook/permissions.md)。

</details>

<details>
<summary>Access Denied</summary>

只授权了目录时，路径要写到授权目录，例如 `s4/my-bucket/images/`。

</details>

<details>
<summary>mc 打开了一个蓝色的文件管理器</summary>

运行的是 Midnight Commander。改用完整路径，例如 `~/go/bin/mc`。

</details>
