# Azion CLI purge

The Azion CLI `purge` command removes cached objects before their TTL ends, so the next request fetches the current version from the origin. It sends a [Real-Time Purge](/en/documentation/platform/applications/cache/real-time-purge/) of one of three types: a list of URLs, a list of cache keys, or one wildcard expression. The purge clears the Cache layer by default, or the [Tiered Cache](/en/documentation/platform/applications/cache/tiered-cache/) layer with `--layer tiered_cache`. The options every command accepts, such as `--format`, `--out`, and `-y`, are on [Global options](/en/documentation/devtools/cli/globals/).

---

## Usage

`azion purge` takes the purge type from one of three flags, `--urls`, `--cachekey`, or `--wildcard`:

```bash
azion purge [flags]
```

| Flag         | Short | Type   | Default   | Description                                                                                              |
| ------------ | ----- | ------ | --------- | -------------------------------------------------------------------------------------------------------- |
| `--cachekey` | —     | string | —         | Comma-separated list of cache keys to purge. The only purge type that the `tiered_cache` layer accepts.  |
| `--layer`    | —     | string | `"cache"` | Layer the purge runs on: `cache` or `tiered_cache`.                                                      |
| `--urls`     | —     | string | —         | Comma-separated list of URLs to purge, with or without the scheme.                                       |
| `--wildcard` | —     | string | —         | One wildcard expression, a URL or a cache key with an asterisk (`*`), that matches the objects to purge. |

A URL without a scheme covers both the HTTP and the HTTPS copies of the object. A wildcard purge takes one expression per request, so a second expression fails with `Only one item is allowed for the Wildcard option`. URL and wildcard purges run on the `cache` layer only: with `--layer tiered_cache`, they fail with `Invalid purge layer for purge type "url".`, or the same error naming `"wildcard"`. For the format of each argument, refer to [Real-Time Purge](/en/documentation/platform/applications/cache/real-time-purge/).

---

## Examples

Each example shows the command and the output it prints.

### Purge a list of URLs

This command purges two pages of a site from the Cache layer:

```bash
azion purge --urls 'xxxxxxxxxx.map.azionedge.net/index.html,xxxxxxxxxx.map.azionedge.net/about.html'
```

The command confirms the purge:

```text
Purge carried out successfully
```

The same command accepts each URL with its scheme, such as `https://xxxxxxxxxx.map.azionedge.net/index.html`.

### Purge with a wildcard expression

This command purges every object under the root path of a site:

```bash
azion purge --wildcard 'xxxxxxxxxx.map.azionedge.net/*'
```

The command confirms the purge:

```text
Purge carried out successfully
```

### Purge a list of cache keys

This command purges the cache keys of two pages from the Cache layer:

```bash
azion purge --cachekey 'xxxxxxxxxx.map.azionedge.net/index.html,xxxxxxxxxx.map.azionedge.net/about.html'
```

The command confirms the purge:

```text
Purge carried out successfully
```

### Purge a cache key from Tiered Cache

This command purges one cache key from the Tiered Cache layer:

```bash
azion purge --cachekey 'xxxxxxxxxx.map.azionedge.net/index.html' --layer tiered_cache
```

The command confirms the purge:

```text
Purge carried out successfully
```

### Choose the purge type at a prompt

In a terminal, the command asks for the purge type when you pass no purge type flag:

```bash
azion purge
```

The command lists the three purge types:

```text
? Choose a purge type:  [Use arrows to move, type to filter]
> URL
  Wildcard
  Cache Key
```

After you choose *URL*, the command asks `Enter the URLs you wish to purge, separated by commas`. Without a terminal, such as in a script, the command fails with `Error: EOF`, so pass `--urls`, `--cachekey`, or `--wildcard` instead.

---

## Related resources

- [Global options](/en/documentation/devtools/cli/globals.md): The options every command accepts, such as `--debug`, `--format`, and `-y`.
- [Purge cached content](/en/documentation/guides/application-performance/cache-and-purge/purge-cached-content.md): The steps to purge content from Azion Console, the API, or the CLI.
- [Cache keys](/en/documentation/platform/applications/cache/cache-keys.md): How a cache key is built, which decides the keys you pass to `--cachekey`.
- [Azion CLI warmup](/en/documentation/devtools/cli/warmup.md): The command that crawls a site and preloads its pages into the cache.
