256 colors
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
52
53
54
55
56
57
88
89
90
91
92
93
124
125
126
127
128
129
160
161
162
163
164
165
196
197
198
199
200
201
22
23
24
25
26
27
58
59
60
61
62
63
94
95
96
97
98
99
130
131
132
133
134
135
166
167
168
169
170
171
202
203
204
205
206
207
28
29
30
31
32
33
64
65
66
67
68
69
100
101
102
103
104
105
136
137
138
139
140
141
172
173
174
175
176
177
208
209
210
211
212
213
34
35
36
37
38
39
70
71
72
73
74
75
106
107
108
109
110
111
142
143
144
145
146
147
178
179
180
181
182
183
214
215
216
217
218
219
40
41
42
43
44
45
76
77
78
79
80
81
112
113
114
115
116
117
148
149
150
151
152
153
184
185
186
187
188
189
220
221
222
223
224
225
46
47
48
49
50
51
82
83
84
85
86
87
118
119
120
121
122
123
154
155
156
157
158
159
190
191
192
193
194
195
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
52
53
54
55
56
57
88
89
90
91
92
93
124
125
126
127
128
129
160
161
162
163
164
165
196
197
198
199
200
201
22
23
24
25
26
27
58
59
60
61
62
63
94
95
96
97
98
99
130
131
132
133
134
135
166
167
168
169
170
171
202
203
204
205
206
207
28
29
30
31
32
33
64
65
66
67
68
69
100
101
102
103
104
105
136
137
138
139
140
141
172
173
174
175
176
177
208
209
210
211
212
213
34
35
36
37
38
39
70
71
72
73
74
75
106
107
108
109
110
111
142
143
144
145
146
147
178
179
180
181
182
183
214
215
216
217
218
219
40
41
42
43
44
45
76
77
78
79
80
81
112
113
114
115
116
117
148
149
150
151
152
153
184
185
186
187
188
189
220
221
222
223
224
225
46
47
48
49
50
51
82
83
84
85
86
87
118
119
120
121
122
123
154
155
156
157
158
159
190
191
192
193
194
195
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
52
53
54
55
56
57
88
89
90
91
92
93
124
125
126
127
128
129
160
161
162
163
164
165
196
197
198
199
200
201
22
23
24
25
26
27
58
59
60
61
62
63
94
95
96
97
98
99
130
131
132
133
134
135
166
167
168
169
170
171
202
203
204
205
206
207
28
29
30
31
32
33
64
65
66
67
68
69
100
101
102
103
104
105
136
137
138
139
140
141
172
173
174
175
176
177
208
209
210
211
212
213
34
35
36
37
38
39
70
71
72
73
74
75
106
107
108
109
110
111
142
143
144
145
146
147
178
179
180
181
182
183
214
215
216
217
218
219
40
41
42
43
44
45
76
77
78
79
80
81
112
113
114
115
116
117
148
149
150
151
152
153
184
185
186
187
188
189
220
221
222
223
224
225
46
47
48
49
50
51
82
83
84
85
86
87
118
119
120
121
122
123
154
155
156
157
158
159
190
191
192
193
194
195
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

Using xterm color codes

For an example of using xterm color codes, try the following command in bash or your favorite xterm terminal. Most of them have 256-color support these days.
echo $(tput setaf 214)256 $(tput setaf 202)colors
You can also use printf in bash
printf "$(tput setaf 214)256 $(tput setaf 202)colors"
Or try the equivalent command using ANSI control sequences
echo -e "\e[38;5;214m256 \e[38;5;202mcolors"
All of the above commands will show colored foreground text
256 colors
For colored background text, you can use `tput setab`
echo $(tput setab 214)256 $(tput setab 202)colors
Which gives you the following colored output
256 colors

Color codes in a shell prompt

When using color codes as part of a shell (bash, zsh) prompt, make sure to enclose them with brackets to tell the shell that they're non-printing characters that take up no space.
\[$(tput setaf 214)256\]
Without brackets, the command prompt will wrap incorrectly when typing a really long command. You may also want to tell the shell to reset the colors at the end of the prompt.
\[$(tput sgr0)\]
Here's a simple example of a colored bash prompt
export PS1='\[$(tput setaf 82)\]\W $ \[$(tput sgr0)\]'
Which gives you this when in the home directory
~ $

Using colors in bash prompts

Here's another example of a bash prompt with colors
export PS1="\[$(tput setaf 34)\]\u\[$(tput setaf 40)\]@\[$(tput setaf 46)\]\h \[$(tput setaf 154)\]\w \[$(tput sgr0)\]$ "
The above prompt will look like this
user@hostname ~/path/to/directory $
For a way to try out different colors in a bash prompt, try going to this
bash prompt generator

Table of color codes

The colors in the table show the default xterm colors. If you've modified your terminal color scheme, the first 16 color codes will show up differently.

color code hex ansi color code
0 #000000 \e[38;5;0m
1 #800000 \e[38;5;1m
2 #008000 \e[38;5;2m
3 #808000 \e[38;5;3m
4 #000080 \e[38;5;4m
5 #800080 \e[38;5;5m
6 #008080 \e[38;5;6m
7 #c0c0c0 \e[38;5;7m
8 #808080 \e[38;5;8m
9 #ff0000 \e[38;5;9m
10 #00ff00 \e[38;5;10m
11 #ffff00 \e[38;5;11m
12 #0000ff \e[38;5;12m
13 #ff00ff \e[38;5;13m
14 #00ffff \e[38;5;14m
15 #ffffff \e[38;5;15m
16 #000000 \e[38;5;16m
17 #00005f \e[38;5;17m
18 #000087 \e[38;5;18m
19 #0000af \e[38;5;19m
20 #0000d7 \e[38;5;20m
21 #0000ff \e[38;5;21m
22 #005f00 \e[38;5;22m
23 #005f5f \e[38;5;23m
24 #005f87 \e[38;5;24m
25 #005faf \e[38;5;25m
26 #005fd7 \e[38;5;26m
27 #005fff \e[38;5;27m
28 #008700 \e[38;5;28m
29 #00875f \e[38;5;29m
30 #008787 \e[38;5;30m
31 #0087af \e[38;5;31m
32 #0087d7 \e[38;5;32m
33 #0087ff \e[38;5;33m
34 #00af00 \e[38;5;34m
35 #00af5f \e[38;5;35m
36 #00af87 \e[38;5;36m
37 #00afaf \e[38;5;37m
38 #00afd7 \e[38;5;38m
39 #00afff \e[38;5;39m
40 #00d700 \e[38;5;40m
41 #00d75f \e[38;5;41m
42 #00d787 \e[38;5;42m
43 #00d7af \e[38;5;43m
44 #00d7d7 \e[38;5;44m
45 #00d7ff \e[38;5;45m
46 #00ff00 \e[38;5;46m
47 #00ff5f \e[38;5;47m
48 #00ff87 \e[38;5;48m
49 #00ffaf \e[38;5;49m
50 #00ffd7 \e[38;5;50m
51 #00ffff \e[38;5;51m
52 #5f0000 \e[38;5;52m
53 #5f005f \e[38;5;53m
54 #5f0087 \e[38;5;54m
55 #5f00af \e[38;5;55m
56 #5f00d7 \e[38;5;56m
57 #5f00ff \e[38;5;57m
58 #5f5f00 \e[38;5;58m
59 #5f5f5f \e[38;5;59m
60 #5f5f87 \e[38;5;60m
61 #5f5faf \e[38;5;61m
62 #5f5fd7 \e[38;5;62m
63 #5f5fff \e[38;5;63m
64 #5f8700 \e[38;5;64m
65 #5f875f \e[38;5;65m
66 #5f8787 \e[38;5;66m
67 #5f87af \e[38;5;67m
68 #5f87d7 \e[38;5;68m
69 #5f87ff \e[38;5;69m
70 #5faf00 \e[38;5;70m
71 #5faf5f \e[38;5;71m
72 #5faf87 \e[38;5;72m
73 #5fafaf \e[38;5;73m
74 #5fafd7 \e[38;5;74m
75 #5fafff \e[38;5;75m
76 #5fd700 \e[38;5;76m
77 #5fd75f \e[38;5;77m
78 #5fd787 \e[38;5;78m
79 #5fd7af \e[38;5;79m
80 #5fd7d7 \e[38;5;80m
81 #5fd7ff \e[38;5;81m
82 #5fff00 \e[38;5;82m
83 #5fff5f \e[38;5;83m
84 #5fff87 \e[38;5;84m
85 #5fffaf \e[38;5;85m
86 #5fffd7 \e[38;5;86m
87 #5fffff \e[38;5;87m
88 #870000 \e[38;5;88m
89 #87005f \e[38;5;89m
90 #870087 \e[38;5;90m
91 #8700af \e[38;5;91m
92 #8700d7 \e[38;5;92m
93 #8700ff \e[38;5;93m
94 #875f00 \e[38;5;94m
95 #875f5f \e[38;5;95m
96 #875f87 \e[38;5;96m
97 #875faf \e[38;5;97m
98 #875fd7 \e[38;5;98m
99 #875fff \e[38;5;99m
100 #878700 \e[38;5;100m
101 #87875f \e[38;5;101m
102 #878787 \e[38;5;102m
103 #8787af \e[38;5;103m
104 #8787d7 \e[38;5;104m
105 #8787ff \e[38;5;105m
106 #87af00 \e[38;5;106m
107 #87af5f \e[38;5;107m
108 #87af87 \e[38;5;108m
109 #87afaf \e[38;5;109m
110 #87afd7 \e[38;5;110m
111 #87afff \e[38;5;111m
112 #87d700 \e[38;5;112m
113 #87d75f \e[38;5;113m
114 #87d787 \e[38;5;114m
115 #87d7af \e[38;5;115m
116 #87d7d7 \e[38;5;116m
117 #87d7ff \e[38;5;117m
118 #87ff00 \e[38;5;118m
119 #87ff5f \e[38;5;119m
120 #87ff87 \e[38;5;120m
121 #87ffaf \e[38;5;121m
122 #87ffd7 \e[38;5;122m
123 #87ffff \e[38;5;123m
124 #af0000 \e[38;5;124m
125 #af005f \e[38;5;125m
126 #af0087 \e[38;5;126m
127 #af00af \e[38;5;127m
128 #af00d7 \e[38;5;128m
129 #af00ff \e[38;5;129m
130 #af5f00 \e[38;5;130m
131 #af5f5f \e[38;5;131m
132 #af5f87 \e[38;5;132m
133 #af5faf \e[38;5;133m
134 #af5fd7 \e[38;5;134m
135 #af5fff \e[38;5;135m
136 #af8700 \e[38;5;136m
137 #af875f \e[38;5;137m
138 #af8787 \e[38;5;138m
139 #af87af \e[38;5;139m
140 #af87d7 \e[38;5;140m
141 #af87ff \e[38;5;141m
142 #afaf00 \e[38;5;142m
143 #afaf5f \e[38;5;143m
144 #afaf87 \e[38;5;144m
145 #afafaf \e[38;5;145m
146 #afafd7 \e[38;5;146m
147 #afafff \e[38;5;147m
148 #afd700 \e[38;5;148m
149 #afd75f \e[38;5;149m
150 #afd787 \e[38;5;150m
151 #afd7af \e[38;5;151m
152 #afd7d7 \e[38;5;152m
153 #afd7ff \e[38;5;153m
154 #afff00 \e[38;5;154m
155 #afff5f \e[38;5;155m
156 #afff87 \e[38;5;156m
157 #afffaf \e[38;5;157m
158 #afffd7 \e[38;5;158m
159 #afffff \e[38;5;159m
160 #d70000 \e[38;5;160m
161 #d7005f \e[38;5;161m
162 #d70087 \e[38;5;162m
163 #d700af \e[38;5;163m
164 #d700d7 \e[38;5;164m
165 #d700ff \e[38;5;165m
166 #d75f00 \e[38;5;166m
167 #d75f5f \e[38;5;167m
168 #d75f87 \e[38;5;168m
169 #d75faf \e[38;5;169m
170 #d75fd7 \e[38;5;170m
171 #d75fff \e[38;5;171m
172 #d78700 \e[38;5;172m
173 #d7875f \e[38;5;173m
174 #d78787 \e[38;5;174m
175 #d787af \e[38;5;175m
176 #d787d7 \e[38;5;176m
177 #d787ff \e[38;5;177m
178 #d7af00 \e[38;5;178m
179 #d7af5f \e[38;5;179m
180 #d7af87 \e[38;5;180m
181 #d7afaf \e[38;5;181m
182 #d7afd7 \e[38;5;182m
183 #d7afff \e[38;5;183m
184 #d7d700 \e[38;5;184m
185 #d7d75f \e[38;5;185m
186 #d7d787 \e[38;5;186m
187 #d7d7af \e[38;5;187m
188 #d7d7d7 \e[38;5;188m
189 #d7d7ff \e[38;5;189m
190 #d7ff00 \e[38;5;190m
191 #d7ff5f \e[38;5;191m
192 #d7ff87 \e[38;5;192m
193 #d7ffaf \e[38;5;193m
194 #d7ffd7 \e[38;5;194m
195 #d7ffff \e[38;5;195m
196 #ff0000 \e[38;5;196m
197 #ff005f \e[38;5;197m
198 #ff0087 \e[38;5;198m
199 #ff00af \e[38;5;199m
200 #ff00d7 \e[38;5;200m
201 #ff00ff \e[38;5;201m
202 #ff5f00 \e[38;5;202m
203 #ff5f5f \e[38;5;203m
204 #ff5f87 \e[38;5;204m
205 #ff5faf \e[38;5;205m
206 #ff5fd7 \e[38;5;206m
207 #ff5fff \e[38;5;207m
208 #ff8700 \e[38;5;208m
209 #ff875f \e[38;5;209m
210 #ff8787 \e[38;5;210m
211 #ff87af \e[38;5;211m
212 #ff87d7 \e[38;5;212m
213 #ff87ff \e[38;5;213m
214 #ffaf00 \e[38;5;214m
215 #ffaf5f \e[38;5;215m
216 #ffaf87 \e[38;5;216m
217 #ffafaf \e[38;5;217m
218 #ffafd7 \e[38;5;218m
219 #ffafff \e[38;5;219m
220 #ffd700 \e[38;5;220m
221 #ffd75f \e[38;5;221m
222 #ffd787 \e[38;5;222m
223 #ffd7af \e[38;5;223m
224 #ffd7d7 \e[38;5;224m
225 #ffd7ff \e[38;5;225m
226 #ffff00 \e[38;5;226m
227 #ffff5f \e[38;5;227m
228 #ffff87 \e[38;5;228m
229 #ffffaf \e[38;5;229m
230 #ffffd7 \e[38;5;230m
231 #ffffff \e[38;5;231m
232 #080808 \e[38;5;232m
233 #121212 \e[38;5;233m
234 #1c1c1c \e[38;5;234m
235 #262626 \e[38;5;235m
236 #303030 \e[38;5;236m
237 #3a3a3a \e[38;5;237m
238 #444444 \e[38;5;238m
239 #4e4e4e \e[38;5;239m
240 #585858 \e[38;5;240m
241 #606060 \e[38;5;241m
242 #666666 \e[38;5;242m
243 #767676 \e[38;5;243m
244 #808080 \e[38;5;244m
245 #8a8a8a \e[38;5;245m
246 #949494 \e[38;5;246m
247 #9e9e9e \e[38;5;247m
248 #a8a8a8 \e[38;5;248m
249 #b2b2b2 \e[38;5;249m
250 #bcbcbc \e[38;5;250m
251 #c6c6c6 \e[38;5;251m
252 #d0d0d0 \e[38;5;252m
253 #dadada \e[38;5;253m
254 #e4e4e4 \e[38;5;254m
255 #eeeeee \e[38;5;255m

JSON array of color codes

[ #000000, #800000, #008000, #808000, #000080, #800080, #008080, #c0c0c0, #808080, #ff0000, #00ff00, #ffff00, #0000ff, #ff00ff, #00ffff, #ffffff, #000000, #00005f, #000087, #0000af, #0000d7, #0000ff, #005f00, #005f5f, #005f87, #005faf, #005fd7, #005fff, #008700, #00875f, #008787, #0087af, #0087d7, #0087ff, #00af00, #00af5f, #00af87, #00afaf, #00afd7, #00afff, #00d700, #00d75f, #00d787, #00d7af, #00d7d7, #00d7ff, #00ff00, #00ff5f, #00ff87, #00ffaf, #00ffd7, #00ffff, #5f0000, #5f005f, #5f0087, #5f00af, #5f00d7, #5f00ff, #5f5f00, #5f5f5f, #5f5f87, #5f5faf, #5f5fd7, #5f5fff, #5f8700, #5f875f, #5f8787, #5f87af, #5f87d7, #5f87ff, #5faf00, #5faf5f, #5faf87, #5fafaf, #5fafd7, #5fafff, #5fd700, #5fd75f, #5fd787, #5fd7af, #5fd7d7, #5fd7ff, #5fff00, #5fff5f, #5fff87, #5fffaf, #5fffd7, #5fffff, #870000, #87005f, #870087, #8700af, #8700d7, #8700ff, #875f00, #875f5f, #875f87, #875faf, #875fd7, #875fff, #878700, #87875f, #878787, #8787af, #8787d7, #8787ff, #87af00, #87af5f, #87af87, #87afaf, #87afd7, #87afff, #87d700, #87d75f, #87d787, #87d7af, #87d7d7, #87d7ff, #87ff00, #87ff5f, #87ff87, #87ffaf, #87ffd7, #87ffff, #af0000, #af005f, #af0087, #af00af, #af00d7, #af00ff, #af5f00, #af5f5f, #af5f87, #af5faf, #af5fd7, #af5fff, #af8700, #af875f, #af8787, #af87af, #af87d7, #af87ff, #afaf00, #afaf5f, #afaf87, #afafaf, #afafd7, #afafff, #afd700, #afd75f, #afd787, #afd7af, #afd7d7, #afd7ff, #afff00, #afff5f, #afff87, #afffaf, #afffd7, #afffff, #d70000, #d7005f, #d70087, #d700af, #d700d7, #d700ff, #d75f00, #d75f5f, #d75f87, #d75faf, #d75fd7, #d75fff, #d78700, #d7875f, #d78787, #d787af, #d787d7, #d787ff, #d7af00, #d7af5f, #d7af87, #d7afaf, #d7afd7, #d7afff, #d7d700, #d7d75f, #d7d787, #d7d7af, #d7d7d7, #d7d7ff, #d7ff00, #d7ff5f, #d7ff87, #d7ffaf, #d7ffd7, #d7ffff, #ff0000, #ff005f, #ff0087, #ff00af, #ff00d7, #ff00ff, #ff5f00, #ff5f5f, #ff5f87, #ff5faf, #ff5fd7, #ff5fff, #ff8700, #ff875f, #ff8787, #ff87af, #ff87d7, #ff87ff, #ffaf00, #ffaf5f, #ffaf87, #ffafaf, #ffafd7, #ffafff, #ffd700, #ffd75f, #ffd787, #ffd7af, #ffd7d7, #ffd7ff, #ffff00, #ffff5f, #ffff87, #ffffaf, #ffffd7, #ffffff, #080808, #121212, #1c1c1c, #262626, #303030, #3a3a3a, #444444, #4e4e4e, #585858, #606060, #666666, #767676, #808080, #8a8a8a, #949494, #9e9e9e, #a8a8a8, #b2b2b2, #bcbcbc, #c6c6c6, #d0d0d0, #dadada, #e4e4e4, #eeeeee, ]