How can I configure my bash prompt to have a newline before it?

Instead of:

Output1
Output2
kshitiz@ksh$

It should have:

Output1
Output2

kshitiz@ksh$
up vote 8 down vote accepted
cd $HOME
more >> .bashrc << 'EOT'
PS1='\n$USER:$PWD>' ; export PS1
EOT

This will do it permanently for all your future terminal and console sessions.

To refresh your current sessions with this setting :

. ~/.bashrc

Find where ever the prompt is defined on your system, typically I grep for PS1 in /etc/bashrc, /etc/profile.d/* or $HOME/.bash*.

Then add a \n to the beginning of that definition.

So for example on my Fedora 19 system:

[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "

So I'd change this line to this:

[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="\n[\u@\h \W]\\$ "

Alternatively if you don't know where it's being defined you can still change it as you'd like using this trick. In your $HOME/.bashrc file simply add this line to the bottom of the file:

export PS1="\n$PS1"

Example

$ export PS1="\n$PS1"

$ ls
ve2_sq021_sc001_v09.0101.jpg  ve2_sq021_sc001_v09.0103.jpg
ve2_sq021_sc001_v09.0102.jpg  ve2_sq021_sc001_v09.0104.jpg

$ ls
ve2_sq021_sc001_v09.0101.jpg  ve2_sq021_sc001_v09.0103.jpg
ve2_sq021_sc001_v09.0102.jpg  ve2_sq021_sc001_v09.0104.jpg

$ 

Use

PROMPT_COMMAND="echo"

Using

PS1="\n$PS1"

messes up bash's character count if you are using colored prompt, which may lead to incorrect wrapping of terminal commands.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.