How to Shorten the Command Prompt in Linux

Sometimes I’m working in the terminal, and before I realize I find it very difficult to enter anymore commands, and that is because the path that I’m in has become so long that I’m at the end of the console. Here are some ways in which you can shorten the prompt at the terminal.

if you only want to change the current terminal prompt, use the environment variable PS1.

PS1='\u@\u$ '

the preceding example sets the prompt to username@hostname$

if you would like to know in what directory you are, you could use \w instead of \u

PS1='\u@\w$ '

or if you want a really short prompt

PS1='\u$ '

And if you’d like a more colorful prompt, you could try

PS1="\e[0;32m\u@\h$\e[m "

prompt

here’s the format you should follow to add color to your prompt

'\e[x;ym $PS1 \e[m '

where \e is the beginning of color scheme
[x;ym is the color
$PS1 is the terminal options; like: \u:user, \h:hostname, etc…
\e[m is the closing of color scheme
instead of $PS1 you should add what your prompt is eg: \u@\h
\u:username
\h:hostname
\W:current directory
\H:FDQN

in order to make permanent changes to all new open terminal, you would have to edit the .bashrc file
here is a wiki from Arch Linux with a list of color to numbers

Share This!

Add a Comment

Your email address will not be published.

Sign up for our Newsletter

Download "Google Search Pro"

Enter your email and stay on top of things,

Subscribe!