How to decorate your Linux Terminal using Shell?

The Linux terminal appearance can be customized using shell commands and environment variables. While GUI settings provide basic customization, shell commands offer more precise control over colors, fonts, and prompt formatting in Ubuntu-based systems.

Most terminal customizations are handled through environment variables that can be modified using shell commands. The primary variable for controlling the terminal prompt is PS1.

The PS1 Variable

The PS1 variable controls the primary prompt string displayed when the shell is ready to read a command. It uses backslash-escaped special characters to determine what appears at the prompt ?

echo $PS1
\[\e]0;\u@\h: \w\a\]

Common PS1 Arguments

The format contains special arguments that control the prompt display ?

  • \u: the username of the current user

  • \h: the hostname up to the first dot (.) in the Fully-Qualified Domain Name

  • \W: the basename of the current working directory, with $HOME abbreviated with a tilde (~)

  • \$: If the current user is root, display #, $ otherwise

Customizing the PS1 Prompt

The PS1 prompt supports color customization for different elements like hostname and username. Colors are applied using the \e special character at the beginning and m at the end to indicate a color sequence ?

# Set a colorful prompt with green username and blue hostname
export PS1="\[\e[32m\]\u@\[\e[34m\]\h:\[\e[0m\]\w\$ "

Text Settings

Value Meaning
0 Normal Text
1 Bold Text
4 Underlined Text

Text Colors

Value Meaning
30 Black
31 Red
32 Green
33 Yellow
34 Blue

Background Colors

Value Meaning
40 Black
41 Red
42 Green
43 Yellow
44 Blue

Making Changes Permanent

Terminal customizations are temporary by default and reset when the terminal session ends. To make them permanent, add the PS1 export command to your .bashrc file ?

# Edit the .bashrc file
nano ~/.bashrc

# Add your custom PS1 at the end of the file
export PS1="\[\e[32m\]\u@\[\e[34m\]\h:\[\e[0m\]\w\$ "

# Reload the configuration
source ~/.bashrc

Conclusion

Customizing the Linux terminal through shell commands provides more control than GUI settings. Use the PS1 variable with color codes to create personalized prompts, and add them to .bashrc for permanent changes.

Updated on: 2026-03-15T17:36:19+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements