KandZ – Tuts

We like to help…!

Linux CLI 25 🐧 Prompt Customization

a - prompt customization intro
you can customize cli prompt by editing the PS1 variable
for permanent changes edit nano ~/.bashrc for BASH
~/.zshrc for Zsh and ~/.config/fish/config.fish for Fish
example β†’ PS1="TestPrompt " export PS1
and then to apply changes
source ~/.bashrc
but you can test and play with it temporarily by editing the PS1 on the terminal
example to only show the username β†’ PS1="\u "

b - prompt escape codes
Most common escape codes for shell prompt
\d β†’ current date \H β†’ full hostname \h β†’ hostname
\n β†’ new line character \r β†’ carriage return
\t β†’ time in 24 hour format \@ β†’ time in 12 hour format with AM/PM
\u β†’ username \w β†’ working directory \W β†’ last part of the working directory
\! β†’ history id of the command
\[ β†’ start of non-printing character sequence ]\ β†’ end for char sequence
example β†’ shows username - working directory last

c - prompt colors codes
List of colors: \033[30m β†’ Black
\033[30m β†’ Dark gray \033[31m β†’ Red \033[31m β†’ Light red
\033[32m β†’Green \033[32m β†’Light green \033[33m β†’ Brown
\033[34m β†’ Blue \033[34m β†’ Light blue \033[33m β†’ Yellow
\033[35m β†’ Purple \033[35m β†’ Light purple
\033[36m β†’ Cyan \033[36m β†’ Light cyan
\033[37m β†’ Light gray \033[37m β†’ White
example 1 β†’ shows username - working directory last in purple color and then back to white

d - prompt background colors and text format codes
List of background colors: \033[40m β†’ Black
\033[44m β†’ Blue \033[41m β†’ Red \033[45m β†’ Purple
\033[42m β†’ Green \033[46m β†’ Cyan \033[43m β†’ Brown \033[47m β†’ Light gray
example 1 β†’ shows username - working directory last in purple color and white background and then back to default
List of text format codes:
\033[0m β†’ Reset formatting to default. \033[1m β†’ Bold text.
\033[4m β†’ Underline text. \033[7m β†’ inverse
example 1 β†’ shows username - working directory last in purple color and white background, underlined and then back to default

Leave a Reply