> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# 用 CLI 管理应用文件

> 用 squarecloud app file 列出、读取、写入、移动和删除运行中 Square Cloud 应用的文件，无需 commit，二进制文件保持完整。

`squarecloud app file` 是一个远程文件管理器：它直接修改应用中的文件，无需 commit。每个子命令都通过 `--app <appID>` 指定应用，该参数是可选的：参见 [CLI 如何找到你的应用](/zh/cli-reference/quickstart#cli-如何找到你的应用)。

`read` 和 `write` 会原样传输二进制文件。

## `squarecloud app file list`

```bash 用法 theme={"system"}
squarecloud app file list [path] [--app <appID>] [--json]
```

列出应用中的一个文件夹（省略 `path` 时为根目录）：类型、名称、大小和最后修改时间。

```bash theme={"system"}
squarecloud app file list /logs --app <appID>
# 列出指定应用的 logs 文件夹。
```

## `squarecloud app file read`

```bash 用法 theme={"system"}
squarecloud app file read <path> [-o <local file>] [-y] [--app <appID>]
```

| 标志 | 说明 |
| - | - |
| `-o`, `--output <local file>` | 把内容保存到本地文件，而不是打印出来。覆盖现有文件前会先询问。 |
| `-y`, `--yes` | 不经询问直接覆盖现有的本地文件。 |
| `--app <appID>` | 要读取的应用。 |

```bash theme={"system"}
squarecloud app file read config.json
# 把文件打印到 stdout。
```

```bash theme={"system"}
squarecloud app file read config.json -o ./config.backup.json
# 保存到本地。
```

由 `-o` 新建的本地文件只有你可以读取（0600 权限），因为应用文件中经常包含密钥。

## `squarecloud app file write`

```bash 用法 theme={"system"}
squarecloud app file write <path> [--from <local file>] [--app <appID>]
```

| 标志 | 说明 |
| - | - |
| `--from <local file>` | 从本地文件读取内容。不使用此标志时，内容来自 stdin。 |
| `--app <appID>` | 要写入的应用。 |

创建该文件；文件已存在时则覆盖它。

```bash theme={"system"}
squarecloud app file write config.json --from ./config.json
```

```bash theme={"system"}
cat ./config.json | squarecloud app file write config.json --app <appID>
# 把 stdin 写入为文件内容。
```

## `squarecloud app file move`

```bash 用法 theme={"system"}
squarecloud app file move <path> <new path> [--app <appID>]
```

**别名：** `mv`、`rename`

```bash theme={"system"}
squarecloud app file mv old-name.txt new-name.txt
```

## `squarecloud app file delete`

```bash 用法 theme={"system"}
squarecloud app file delete <path> [-y] [--app <appID>]
```

**别名：** `rm`

| 标志 | 说明 |
| - | - |
| `-y`, `--yes` | 跳过确认提示。 |
| `--app <appID>` | 要修改的应用。 |

先要求 `y/N` 确认，然后删除该文件。

```bash theme={"system"}
squarecloud app file rm old-log.txt -y
```

## 相关内容

| 命令 | API | JavaScript SDK |
| - | - | - |
| `list` | [`GET .../files`](/zh/api-reference/endpoint/apps/filemanager/list) | [`api.apps.files.list()`](/zh/sdks/js/managing_files) |
| `read` | [`GET .../files/content`](/zh/api-reference/endpoint/apps/filemanager/content) | [`api.apps.files.read()`](/zh/sdks/js/managing_files) |
| `write` | [`PUT .../files`](/zh/api-reference/endpoint/apps/filemanager/put) | [`api.apps.files.write()`](/zh/sdks/js/managing_files) |
| `move` | [`PATCH .../files`](/zh/api-reference/endpoint/apps/filemanager/patch) | [`api.apps.files.move()`](/zh/sdks/js/managing_files) |
| `delete` | [`DELETE .../files`](/zh/api-reference/endpoint/apps/filemanager/delete) | [`api.apps.files.delete()`](/zh/sdks/js/managing_files) |

要一步发送整个文件夹，请使用 [`squarecloud commit`](/zh/cli-reference/deploy#squarecloud-commit)。
