빠른 참조

ANSI 이스케이프 코드, 터미널 색상 및 커서 제어 치트시트

터미널 애플리케이션용 ANSI 이스케이프 시퀀스 퀵 가이드: 텍스트 스타일(굵게, 밑줄 등), 16색/256색/RGB 전경색 및 배경색, 커서 위치 이동 및 화면 지우기 제어.

· 게시일

Escape Sequence Syntax

In shell scripts, the escape character is typically represented as \033, \e, or \x1b:

\033[<parameters>m

Text Styles

Code Effect
0 Reset / Normal (clears all styles)
1 Bold / Increased intensity
2 Dim / Decreased intensity
3 Italic (not widely supported)
4 Underline
5 Slow Blink
7 Reverse Video (invert foreground & background)
8 Conceal / Hidden
9 Crossed-out / Strikethrough

Standard Colors (3-bit / 4-bit)

Color Name Foreground (Normal) Foreground (Bright) Background (Normal) Background (Bright)
Black 30 90 40 100
Red 31 91 41 101
Green 32 92 42 102
Yellow 33 93 43 103
Blue 34 94 44 104
Magenta 35 95 45 105
Cyan 36 96 46 106
White 37 97 47 107

Examples

# Red bold text
echo -e "\033[1;31mError:\033[0m Something went wrong."

# Green text on black background
echo -e "\033[32;40mSuccess!\033[0m"

Cursor Movement & Screen Clearing

Sequence Action
\033[<n>A Move cursor up <n> lines
\033[<n>B Move cursor down <n> lines
\033[<n>C Move cursor forward (right) <n> columns
\033[<n>D Move cursor backward (left) <n> columns
\033[<line>;<col>H Move cursor to row <line>, column <col>
\033[2J Clear entire screen and home cursor
\033[K or \033[0K Clear line from cursor position to end
\033[1K Clear line from cursor position to beginning
\033[2K Clear entire current line

Helpful Bash Utilities

# Cursor visibility
hide_cursor() { printf "\e[?25l"; }
show_cursor() { printf "\e[?25h"; }

# Text formatting helpers
bold()  { printf "\e[1m%s\e[0m\n" "$*"; }
green() { printf "\e[32m%s\e[0m\n" "$*"; }
red()   { printf "\e[31m%s\e[0m\n" "$*"; }

관련 주제