Shorten Prompt Path in Terminal

Опубликовано: 10 Февраль 2026
на канале: LinuxHowTo
3,776
54

we can shorten terminal path by changing the value of the PS1 (Prompt String 1)
so what is PS1 Prompt ?
it is a inbuilt shell variable

for example tona@tona-pc:~$ is Prompt means that user "tona" is logged in at host "tona-pc"
we can change this prompt format by changing PS1 value
to print its value
#echo $PS1

we can change this format to shorten the path

to see the different formats
#man bash
and then search man page by typeing "/" and search for word "PROMPTING"
Note: we use "n" to search next in man page ; and "N" or "shift+n" to search previous

\H the hostname
\u the username of the current user
\w the current working directory

try this format "username@hostname:current_directory$ "
PS1='\u@\H:\w$ '

to give colors \e[{Text_Format};{Text_Color}mPROMPT_FORMAT\e[0m

\e[{Text_Format};{Text_Color}m : set colors
\e[0m : to reset color and text format to default

{Text_Format} :
0-normal
1-bold
4-underline

{Text_Color} :
30: Black
31: Red
32: Green
33: Yellow
34: Blue
35: Purple
36: Cyan
37: White

lets make some colors
PS1='\e[1;32m\u@\H:\e[0m\e[1;33m\w\e[0m\e[1;35m$\e[0m '


this change is temporary to change it permanently ; change it in .bashrc file