github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/website/source/docs/commands/kv/delete.html.markdown.erb (about) 1 --- 2 layout: "docs" 3 page_title: "Commands: KV Delete" 4 sidebar_current: "docs-commands-kv-delete" 5 --- 6 7 # Consul KV Delete 8 9 Command: `consul kv delete` 10 11 The `kv delete` command removes the value from Consul's KV store at the 12 given path. If no key exists at the path, no action is taken. 13 14 ## Usage 15 16 Usage: `consul kv delete [options] KEY_OR_PREFIX` 17 18 #### API Options 19 20 <%= partial "docs/commands/http_api_options_client" %> 21 <%= partial "docs/commands/http_api_options_server" %> 22 23 #### KV Delete Options 24 25 * `-cas` - Perform a Check-And-Set operation. Specifying this value also 26 requires the -modify-index flag to be set. The default value is false. 27 28 * `-modify-index=<int>` - Unsigned integer representing the ModifyIndex of the 29 key. This is used in combination with the -cas flag. 30 31 * `-recurse` - Recursively delete all keys with the path. The default value is 32 false. 33 34 ## Examples 35 36 To remove the value for the key named "redis/config/connections" in the 37 KV store: 38 39 ``` 40 $ consul kv delete redis/config/connections 41 Success! Deleted key: redis/config/connections 42 ``` 43 44 If the key does not exist, the command will not error, and a success message 45 will be returned: 46 47 ``` 48 $ consul kv delete not-a-real-key 49 Success! Deleted key: not-a-real-key 50 ``` 51 52 To only delete a key if it has not been modified since a given index, specify 53 the `-cas` and `-modify-index` flags: 54 55 ``` 56 $ consul kv get -detailed redis/config/connections | grep ModifyIndex 57 ModifyIndex 456 58 59 $ consul kv delete -cas -modify-index=123 redis/config/connections 60 Error! Did not delete key redis/config/connections: CAS failed 61 62 $ consul kv delete -cas -modify-index=456 redis/config/connections 63 Success! Deleted key: redis/config/connections 64 ``` 65 66 To recursively delete all keys that start with a given prefix, specify the 67 `-recurse` flag: 68 69 ``` 70 $ consul kv delete -recurse redis/ 71 Success! Deleted keys with prefix: redis/ 72 ``` 73 74 !> **Trailing slashes are important** in the recursive delete operation, since 75 Consul performs a greedy match on the provided prefix. If you were to use "foo" 76 as the key, this would recursively delete any key starting with those letters 77 such as "foo", "food", and "football" not just "foo". To ensure you are deleting 78 a folder, always use a trailing slash. 79 80 It is not valid to combine the `-cas` option with `-recurse`, since you are 81 deleting multiple keys under a prefix in a single operation: 82 83 ``` 84 $ consul kv delete -cas -recurse redis/ 85 Cannot specify both -cas and -recurse! 86 ```