---
title: "openemail files"
description: "Every command in this namespace, with its arguments, flags and examples."
url: "https://openemail.uk/docs/cli/reference/files"
area: "CLI"
category: "Reference"
---

# openemail files

Every command in this namespace, with its arguments, flags and examples.

## Commands

### `openemail files list`

List one page of the files the mailbox holds

```bash
openemail files list [flags]
```

Resolves one page of the Files page: every attachment the mailbox holds, sent and received, and every file uploaded to it, with its name, type, size, the address it came to, the thread it belongs to and whether it can be deleted.

Only an upload that nothing depends on can be deleted, and its `deletable` is true. Every other row has a `usage` saying what keeps it: `received`, `sent`, `linked` for an upload that went out as a download link that still works, or `scheduled` for one attached to a message that has not gone out yet.

A key limited to particular addresses or domains sees only the files that arrived at them, the same boundary the thread list uses, so it does not see files uploaded for the whole workspace. A deleted file is not listed.

The index starts from the day it shipped, so an older mailbox lists what has arrived since. Older attachments are still on their messages, where `threads.listAttachments` reads them.

Add `--all` to walk every page: a table on a terminal, one JSON object per line when piped or with `--ndjson`, and one `{ items, hasMore, nextCursor }` document with `--json`. `--max <n>` stops after that many items.

- Scopes: `files:read`.
- Needs a sign-in.
- Aliases: `ls`.

**Flags**

- `--q <value>`: Searches the file name and its type. Words match loosely, and a close spelling is tried when nothing matches exactly.
- `--kind <value>`: Keeps one kind: `image`, `pdf`, `audio`, `video` or `text`, the choices of the filter on the Files page.
- `--direction <value>`: Keeps one direction: `inbound` for files that arrived on a message, `outbound` for files that went out on one, `uploaded` for files put on the Files page.
- `--address <value>`: Keeps the files of one address, the `deliveredTo` of the file, compared without regard to case.
- `--since <when>`: Keeps files added at or after this moment. A `Date` or an ISO 8601 string.
- `--until <when>`: Keeps files added before this moment. A `Date` or an ISO 8601 string.
- `--sort <value>` (default `"newest"`): `newest` (the default), `oldest`, `largest` or `name`. A cursor carries on in the order it was handed out in.
- `--limit <n>` (default `25`): Page size, from 1 to 100. The server defaults to 25.
- `--cursor <value>`: The `nextCursor` of the previous page. Leave it out for the first page.
- `--all`: Fetch every page and stream the items as they arrive.
- `--max <n>`: Stop after this many items. Implies `--all`.
- `--ndjson`: Print every item as one JSON object per line. Implies `--all`

**Examples**

```bash
openemail files list
```

With optional flags

```bash
openemail files list --kind pdf --sort largest
```

Walk every page and stop after 100 items

```bash
openemail files list --all --max 100
```

One JSON object per line when piped

```bash
openemail files list --all > files.ndjson
```

Also available in: API [`GET /files`](https://openemail.uk/docs/api/reference/files#get-files); SDK [`files.list()`](https://openemail.uk/docs/sdk/reference/files#list).

### `openemail files get`

Read one file by id

```bash
openemail files get <id> [flags]
```

Resolves one file: its name, type, size, whether it was sent, received or uploaded, the address it came to, the thread and message it belongs to, and whether it can be deleted. `download` fetches its bytes.

`deletable` is true only for an upload that nothing depends on. Otherwise `usage` says what keeps it: `received` or `sent` for a file that came in or went out on a message, `linked` for an upload that went out as a download link that still works, and `scheduled` for one attached to a message that has not gone out yet.

- Scopes: `files:read`.
- Needs a sign-in.
- Aliases: `show`, `view`.

**Arguments**

- `<id>` (required): The id from `list`, `file_` and 24 hex.

**Examples**

```bash
openemail files get file_6bb640f5b99e47deb758f1f5
```

Print the raw JSON

```bash
openemail files get file_6bb640f5b99e47deb758f1f5 --json
```

Also available in: API [`GET /files/{id}`](https://openemail.uk/docs/api/reference/files#get-files-id); SDK [`files.get()`](https://openemail.uk/docs/sdk/reference/files#get).

### `openemail files stats`

Count the files and the space they take

```bash
openemail files stats [flags]
```

Returns the numbers on the Analytics tab of the Files page in one request: how many files the mailbox holds and how many bytes they take, in all and split into received, sent and uploaded, the file types and the addresses taking the most space, how many files arrived on each of the last 30 days, and the download links still working with how often they were fetched.

Deleted files are not counted. A key limited to particular addresses or domains counts only the files that arrived at them, so files uploaded for the whole workspace are left out of its numbers.

- Scopes: `files:read`.
- Needs a sign-in.

**Examples**

```bash
openemail files stats
```

Print the raw JSON

```bash
openemail files stats --json
```

Also available in: API [`GET /files/stats`](https://openemail.uk/docs/api/reference/files#get-files-stats); SDK [`files.stats()`](https://openemail.uk/docs/sdk/reference/files#stats).

### `openemail files download`

Fetch the bytes of a file

```bash
openemail files download <id> [flags]
```

Resolves with the file exactly as it is stored, the same bytes the Download action on the Files page saves. The response carries the file's own `Content-Type` and name.

- Scopes: `files:read`.
- Needs a sign-in.

**Arguments**

- `<id>` (required): The id from `list`.

**Flags**

- `-o, --out <file>`: Write the file here. Required on a terminal. Without it, piped output gets the raw bytes

**Examples**

```bash
openemail files download file_6bb640f5b99e47deb758f1f5
```

Save the file

```bash
openemail files download file_6bb640f5b99e47deb758f1f5 --out report.pdf
```

Also available in: API [`GET /files/{id}/content`](https://openemail.uk/docs/api/reference/files#get-files-id-content); SDK [`files.download()`](https://openemail.uk/docs/sdk/reference/files#download).

### `openemail files list-links`

List the download links a file went out as

```bash
openemail files list-links <id> [flags]
```

Resolves one page of the download links made for this file, newest first. A large attachment sent from OpenEmail travels as a link rather than inside the message, and each send makes a link of its own. Every row says how often it was fetched, when last, and whether it was revoked. While one of its links still works, an upload cannot be deleted.

A file attached inside a message has no links, because nothing records when those are opened.

Add `--all` to walk every page: a table on a terminal, one JSON object per line when piped or with `--ndjson`, and one `{ items, hasMore, nextCursor }` document with `--json`. `--max <n>` stops after that many items.

- Scopes: `files:read`.
- Needs a sign-in.

**Arguments**

- `<id>` (required): The file id from `list`.

**Flags**

- `--limit <n>` (default `25`): Page size, from 1 to 100. The server defaults to 25.
- `--cursor <value>`: The `nextCursor` of the previous page. Leave it out for the first page.
- `--all`: Fetch every page and stream the items as they arrive.
- `--max <n>`: Stop after this many items. Implies `--all`.
- `--ndjson`: Print every item as one JSON object per line. Implies `--all`

**Examples**

```bash
openemail files list-links file_6bb640f5b99e47deb758f1f5
```

Walk every page and stop after 100 items

```bash
openemail files list-links file_6bb640f5b99e47deb758f1f5 --all --max 100
```

One JSON object per line when piped

```bash
openemail files list-links file_6bb640f5b99e47deb758f1f5 --all > files.ndjson
```

Also available in: API [`GET /files/{id}/links`](https://openemail.uk/docs/api/reference/files#get-files-id-links); SDK [`files.listLinks()`](https://openemail.uk/docs/sdk/reference/files#listLinks).

### `openemail files create-link`

Publish a file at a public link

```bash
openemail files create-link <id> [flags]
```

Makes a public download link for the file and resolves with it. Anybody holding `url` can open the file without signing in, which is how an image or a document is referenced from an email or a web page. Each call makes a new link with its own download count, and a link keeps working until it is revoked with `revokeLink` or the file is deleted.

The link lives on the files host of `--domain` when that domain has one set up, such as `files.acme.com`, else on the files host of the address the file belongs to, else on the OpenEmail API address. A file that came in or went out on a message is copied to public storage first. Programs and scripts are refused with 422 `file_unshareable`.

- Scopes: `files:write`.
- Needs a sign-in.

**Arguments**

- `<id>` (required): The file id from `list`.

**Flags**

- `--domain <value>`: The domain whose files host serves the link, such as `acme.com`.

**Examples**

The required values only

```bash
openemail files create-link file_6bb640f5b99e47deb758f1f5
```

With optional flags

```bash
openemail files create-link file_6bb640f5b99e47deb758f1f5 --domain acme.com
```

Also available in: API [`POST /files/{id}/links`](https://openemail.uk/docs/api/reference/files#post-files-id-links); SDK [`files.createLink()`](https://openemail.uk/docs/sdk/reference/files#createLink).

### `openemail files revoke-link`

Revoke a public link

```bash
openemail files revoke-link <id> <link-id> [flags]
```

Stops a public link from working, for good, including in mail that already went out with it, and resolves with the link, `revokedAt` set. Revoking a link that is already revoked resolves with it unchanged, so the call is safe to repeat. An unknown link is a 404.

- Scopes: `files:write`.
- Needs a sign-in.
- Asks you to confirm.

**Arguments**

- `<id>` (required): The file id from `list`.
- `<link-id>` (required): The link id from `listLinks` or `createLink`.

**Examples**

```bash
openemail files revoke-link file_6bb640f5b99e47deb758f1f5 shr_2f9c4a1e7b3d
```

Skip the confirmation, for scripts

```bash
openemail files revoke-link file_6bb640f5b99e47deb758f1f5 shr_2f9c4a1e7b3d --yes
```

Also available in: API [`DELETE /files/{id}/links/{linkId}`](https://openemail.uk/docs/api/reference/files#delete-files-id-links-linkid); SDK [`files.revokeLink()`](https://openemail.uk/docs/sdk/reference/files#revokeLink).

### `openemail files revoke-all-links`

Revoke every link to a file

```bash
openemail files revoke-all-links <id> [flags]
```

Makes the file private, as Make private on the Files page does: every public download link to it stops working at once, including the ones in mail that already went out. Resolves with `revoked`, how many links were still working. The file itself stays, and `createLink` can publish it again at a new link.

A key limited to particular addresses reaches only the files that arrived at them, and any other file is a 404.

- Scopes: `files:write`.
- Needs a sign-in.
- Asks you to confirm.

**Arguments**

- `<id>` (required): The file id from `list`.

**Examples**

```bash
openemail files revoke-all-links file_6bb640f5b99e47deb758f1f5
```

Skip the confirmation, for scripts

```bash
openemail files revoke-all-links file_6bb640f5b99e47deb758f1f5 --yes
```

Also available in: API [`DELETE /files/{id}/links`](https://openemail.uk/docs/api/reference/files#delete-files-id-links); SDK [`files.revokeAllLinks()`](https://openemail.uk/docs/sdk/reference/files#revokeAllLinks).

### `openemail files upload`

Upload a file to the Files page

```bash
openemail files upload <data> [flags]
```

Stores the bytes as a new file, the way the Upload button on the Files page does, and resolves with it: `direction` is `uploaded`, `usage` is null and `deletable` is true. Attach it to a send as `{ fileId }` in `emails.send`, which is how a file larger than the inline cap goes out.

`data` is a `Blob`, an `ArrayBuffer` or a `Uint8Array`, sent as the request body. The name travels as the `filename` query parameter, and it is cleaned rather than refused: characters a file name cannot hold become `_`, and a name longer than 255 characters is cut, keeping its extension. The type is `--content-type`, or a `Blob`'s own type when that is left out, and `application/octet-stream` without either. A value that is not shaped like a MIME type is stored as `application/octet-stream` too.

A key limited to particular addresses or domains uploads to the first address it holds, which becomes `deliveredTo`. An unlimited key uploads for the whole workspace and `deliveredTo` is null, so a narrowed key never reaches that file afterwards.

- Scopes: `files:write`.
- Needs a sign-in.

**Arguments**

- `<data>` (required): The file: a `Blob`, `ArrayBuffer` or `Uint8Array`, not empty and at most 100 MB.

**Flags**

- `--filename <value>`: The name the file is stored and downloaded under, such as `report.pdf`. A missing or blank name throws before anything is sent.
- `--content-type <value>`: The MIME type, such as `application/pdf`. Left out, a `Blob`'s own type is used, else `application/octet-stream`.
- `--timeout-ms <n>`: How long the upload may take, in milliseconds. Left out, it is 10 minutes, or the client `--timeout-ms` when that is longer. `0` waits as long as it takes.

**Examples**

The required values only

```bash
openemail files upload ./photo.jpg
```

With optional flags

```bash
openemail files upload ./photo.jpg --filename report.pdf --content-type application/pdf
```

Also available in: API [`POST /files`](https://openemail.uk/docs/api/reference/files#post-files); SDK [`files.upload()`](https://openemail.uk/docs/sdk/reference/files#upload).

### `openemail files delete`

Delete an uploaded file for good

```bash
openemail files delete <id> [flags]
```

Removes an uploaded file: its bytes are deleted from storage and it leaves the Files page. The row stays, marked deleted, so the index knows the file existed. There is no undo.

Only an upload that nothing depends on can be deleted, the files whose `deletable` is true. A file that was received or sent stays with its message, and so does an upload that went out as a download link that still works or is attached to a message that has not gone out yet. Those are refused with 409 `file_in_use`, and the message names the file and says why. An upload that was sent inside a message can still be deleted, because the message keeps its own copy, which is listed as a separate `sent` file.

`deleteMany` deletes up to 100 in one call and reports the ones it kept instead of failing.

- Scopes: `files:write`.
- Needs a sign-in.
- Asks you to confirm.
- Aliases: `rm`, `del`, `remove`.

**Arguments**

- `<id>` (required): The id from `list`.

**Examples**

```bash
openemail files delete file_6bb640f5b99e47deb758f1f5
```

Skip the confirmation, for scripts

```bash
openemail files delete file_6bb640f5b99e47deb758f1f5 --yes
```

Also available in: API [`DELETE /files/{id}`](https://openemail.uk/docs/api/reference/files#delete-files-id); SDK [`files.delete()`](https://openemail.uk/docs/sdk/reference/files#delete).

### `openemail files delete-many`

Delete up to 100 files in one call

```bash
openemail files delete-many <ids...> [flags]
```

Deletes every file in `ids` that can be deleted, the way `delete` deletes one, and reports the rest instead of failing. It is what selecting several files on the Files page and pressing Delete does.

Only an uploaded file that nothing depends on can be deleted. A file that was received or sent stays with its message, and so does an upload that went out as a download link that still works or is attached to a message that has not gone out yet. Each of those comes back in `kept` with its `usage` and a `reason` in plain words. An id that is unknown, already deleted or outside the addresses a narrowed key holds comes back in `missing`. The rule is checked again at the moment of deleting, so a file that became used in between is kept.

There is no undo.

- Scopes: `files:write`.
- Needs a sign-in.
- Asks you to confirm.

**Arguments**

- `<ids...>` (required): 1 to 100 file ids from `list`. More than 100, or none, is a 422 on `ids`. A repeated id counts once.

**Examples**

```bash
openemail files delete-many file_6bb640f5b99e47deb758f1f5
```

Skip the confirmation, for scripts

```bash
openemail files delete-many file_6bb640f5b99e47deb758f1f5 --yes
```

Also available in: API [`POST /files/batch-delete`](https://openemail.uk/docs/api/reference/files#post-files-batch-delete); SDK [`files.deleteMany()`](https://openemail.uk/docs/sdk/reference/files#deleteMany).
