1---
2layout: commands
3page_title: 'Commands: KV Get'
4---
5
6# Consul KV Get
7
8Command: `consul kv get`
9
10The `kv get` command is used to retrieve the value from Consul's KV
11store at the given key name. If no key exists with that name, an error is
12returned. If a key exists with that name but has no data, nothing is returned.
13A key name or prefix is required.
14
15## Usage
16
17Usage: `consul kv get [options] [KEY_OR_PREFIX]`
18
19#### API Options
20
21@include 'http_api_options_client.mdx'
22
23@include 'http_api_options_server.mdx'
24
25#### Enterprise Options
26
27@include 'http_api_namespace_options.mdx'
28
29#### KV Get Options
30
31- `-base64` - Base 64 encode the value. The default value is false.
32
33- `-detailed` - Provide additional metadata about the key in addition to the
34  value such as the ModifyIndex and any flags that may have been set on the key.
35  The default value is false.
36
37- `-keys` - List keys which start with the given prefix, but not their values.
38  This is especially useful if you only need the key names themselves. This
39  option is commonly combined with the -separator option. The default value is
40  false.
41
42- `-recurse` - Recursively look at all keys prefixed with the given path. The
43  default value is false.
44
45- `-separator=<string>` - String to use as a separator for recursive lookups. The
46  default value is "/", and only used when paired with the `-keys` flag. This will
47  limit the prefix of keys returned, only up to the given separator.
48
49## Examples
50
51To retrieve the value for the key named "redis/config/connections" in the
52KV store:
53
54```shell-session
55$ consul kv get redis/config/connections
565
57```
58
59This will return the original, raw value stored in Consul. To view detailed
60information about the key, specify the "-detailed" flag. This will output all
61known metadata about the key including ModifyIndex and any user-supplied
62flags:
63
64```shell-session
65$ consul kv get -detailed redis/config/connections
66CreateIndex      336
67Flags            0
68Key              redis/config/connections
69LockIndex        0
70ModifyIndex      336
71Session          -
72Value            5
73```
74
75If the key with the given name does not exist, an error is returned:
76
77```shell-session
78$ consul kv get not-a-real-key
79Error! No key exists at: not-a-real-key
80```
81
82To treat the path as a prefix and list all keys which start with the given
83prefix, specify the "-recurse" flag:
84
85```shell-session
86$ consul kv get -recurse redis/
87redis/config/connections:5
88redis/config/cpu:128
89redis/config/memory:512
90```
91
92Or list detailed information about all pairs under a prefix:
93
94```shell-session
95$ consul kv get -recurse -detailed redis
96CreateIndex      336
97Flags            0
98Key              redis/config/connections
99LockIndex        0
100ModifyIndex      336
101Session          -
102Value            5
103
104CreateIndex      472
105Flags            0
106Key              redis/config/cpu
107LockIndex        0
108ModifyIndex      472
109Session          -
110Value            128
111
112CreateIndex      471
113Flags            0
114Key              redis/config/memory
115LockIndex        0
116ModifyIndex      471
117Session          -
118Value            512
119```
120
121To just list the keys which start with the specified prefix, use the "-keys"
122option instead. This is more performant and results in a smaller payload:
123
124```shell-session
125$ consul kv get -keys redis/config/
126redis/config/connections
127redis/config/cpu
128redis/config/memory
129```
130
131By default, the `-keys` operation uses a separator of "/", meaning it will not
132recurse beyond that separator. You can choose a different separator by setting
133`-separator="<string>"`.
134
135```shell-session
136$ consul kv get -keys -separator="c" redis
137redis/c
138```
139
140Alternatively, you can disable the separator altogether by setting it to the
141empty string:
142
143```shell-session
144$ consul kv get -keys -separator="" redis
145redis/config/connections
146redis/config/cpu
147redis/config/memory
148```
149
150To list all keys at the root, simply omit the prefix parameter:
151
152```shell-session
153$ consul kv get -keys
154memcached/
155redis/
156```
157