> ## 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 アプリのファイルを一覧、読み取り、書き込み、移動、削除します。バイナリもそのまま扱えます。

`squarecloud app file` はリモートのファイルマネージャーです。コミットを行わずに、アプリケーション内のファイルを直接変更します。すべてのサブコマンドは `--app <appID>` でアプリケーションを受け取ります。これは省略できます。[CLI がアプリを特定する仕組み](/ja/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>
# Lists the logs folder of a specific app.
```

## `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
# Prints the file to stdout.
```

```bash theme={"system"}
squarecloud app file read config.json -o ./config.backup.json
# Saves it locally.
```

アプリケーションのファイルには機密情報が含まれることが多いため、`-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>
# Writes stdin as the file content.
```

## `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`](/ja/api-reference/endpoint/apps/filemanager/list) | [`api.apps.files.list()`](/ja/sdks/js/managing_files) |
| `read` | [`GET .../files/content`](/ja/api-reference/endpoint/apps/filemanager/content) | [`api.apps.files.read()`](/ja/sdks/js/managing_files) |
| `write` | [`PUT .../files`](/ja/api-reference/endpoint/apps/filemanager/put) | [`api.apps.files.write()`](/ja/sdks/js/managing_files) |
| `move` | [`PATCH .../files`](/ja/api-reference/endpoint/apps/filemanager/patch) | [`api.apps.files.move()`](/ja/sdks/js/managing_files) |
| `delete` | [`DELETE .../files`](/ja/api-reference/endpoint/apps/filemanager/delete) | [`api.apps.files.delete()`](/ja/sdks/js/managing_files) |

フォルダ全体を一度に送信するには、[`squarecloud commit`](/ja/cli-reference/deploy#squarecloud-commit) を使います。
