---
title: "calicoctl replace"
description: "Reference for the calicoctl replace command in Calico Open Source, used to replace an existing resource with one defined in a manifest."
product: "Calico Open Source"
version: "3.33 (latest)"
section: "Reference"
canonical_url: "https://docs.tigera.io/calico/latest/reference/calicoctl/replace"
---

# calicoctl replace

This sections describes the `calicoctl replace` command.

Read the [calicoctl command line interface user reference](https://docs.tigera.io/calico/latest/reference/calicoctl/overview.md) for a full list of calicoctl commands.

> **SECONDARY:** The available actions for a specific resource type may be limited based on the datastore used for Calico (etcdv3 / Kubernetes API). Please refer to the [Resources section](https://docs.tigera.io/calico/latest/reference/resources/overview.md) for details about each resource type.

## Displaying the help text for 'calicoctl replace' command

Run `calicoctl replace --help` to display the following help menu for the command.

```text
Replace one or more existing Calico resources from a file, directory, or stdin,
in YAML or JSON format. Replace fails if a resource doesn't already exist; use
apply if you want it created in that case.

Usage:
  calicoctl replace [flags]

Examples:
  # Replace resources from a file.
  calicoctl replace -f ./policy.yaml

Flags:
  -c, --config string      Path to the file containing connection configuration in YAML or JSON format. (default "/etc/calico/calicoctl.cfg")
  -f, --filename string    Filename to use to create/apply/replace/delete the resource. Use '-' for stdin.
  -h, --help               help for replace
  -n, --namespace string   Namespace of the resource.
  -R, --recursive          Process the filename specified in -f recursively.
      --skip-empty         Do not error if files contain no data.

Global Flags:
      --allow-version-mismatch   Allow client and cluster versions mismatch
      --context string           The name of the kubeconfig context to use
  -l, --log-level string         Set the log level (panic, fatal, error, warn, info, debug) (default "panic")
```

### Examples

1. Replace a set of resources (of mixed type) using the data in resources.yaml.

   ```bash
   calicoctl replace -f ./resources.yaml
   ```

   Results indicate that 8 resources were successfully replaced.

   ```text
   Successfully replaced 8 resource(s)
   ```

2. Replace a policy based on the JSON passed into stdin.

   ```bash
   cat policy.json | calicoctl replace -f -
   ```

   Results indicate the policy does not exist.

   ```text
   Failed to replace any 'policy' resources: resource does not exist: Policy(name=dbPolicy)
   ```

### Options

```text
  -f, --filename string    Filename to use to create/apply/replace/delete the resource. Use '-' for stdin.
```

### General options

```text
  -c, --config string      Path to the file containing connection configuration in YAML or JSON format. (default "/etc/calico/calicoctl.cfg")
```

## See also

- [Installing calicoctl](https://docs.tigera.io/calico/latest/operations/calicoctl/install.md)
- [Resources](https://docs.tigera.io/calico/latest/reference/resources/overview.md) for details on all valid resources, including file format and schema
- [NetworkPolicy](https://docs.tigera.io/calico/latest/reference/resources/networkpolicy.md) for details on the Calico selector-based policy model
