53

I wish to add a new line on every prompt. Instead of the cursor showing on the line as name@machine:~$ _,

I want it to be on the next line, like as:

name@machine:~$
_

Thanks.

69
  • Open the file ~/.bashrc (or /etc/bash.bashrc if it should work globally for all users).

  • Locate the variable called PS1.

  • Simply put an \n at the end of the value of the PS1 variable.

  • 18
    The easiest way to do this is to add PS1="$PS1\n" to the bottom of your ~/.bashrc file. – Dennis VanMeter Dec 6 '10 at 14:09
  • 3
    Guess that's easier to maintain - why don't make it a new answer? :) – htorque Dec 6 '10 at 14:44
  • yeah, I did that. there were too many lines to append a \n to, So i created a new variable. – theTuxRacer Dec 6 '10 at 17:04
8

I prefer using a custom .bashrc file

First, append the following lines to your ~/.bashrc file:

##
## INCLUDE CUSTOM `.bashrc` CODE
##
if [ -f ~/.bashrc_custom ]; then
    . ~/.bashrc_custom
fi

Create the custom file:

touch ~/.bashrc_custom`

Finally open it and put the following lines into:

# File: $HOME/.bashrc_custom
# THIS FILE IS A USER-CUSTOM BASHRC FILE TO KEEP CLEAN THE DEFAULT ~/.barshrc FILE.
# PUT THERE ANY CUSTOM CODE MANUALLY ADDED BY YOU


# Add a new line at the end of the command prompt
#PS1=${PS1}\\n
PS1=${PS1%?}
PS1=${PS1%?}\n'$ '

The next opened shell session will looks like following:

user@host:~
$ <your-next-command-will-be-rendered-here>
  • 4
    Why do you recommend using custom .bashrc file? Isn't exactly why .bashrc in your home directory exists? I understand that you can use and modify default generated .bashrc, but than when you want to use .bashrc on other OSes you can't because you depend on default .bashrc file and if it's not the same it can behave differently. – Michal Bernhard Nov 24 '17 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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