The default BASH Prompt

You may find the default BASH prompt to be sufficient. It usually tells you which user you’re logged in as, which machine, and the present working directory. All very nice.


Why would you change the default?

As many of us only use linux in a single-user scenario, knowing the username is kind of pointless, as you should already know that. I’ll show you my prompt and then explain how I got there.

my prompt

Marax is the machine name I’m using to write this post, and it has the PWD or present working directory. I prefer this look and I have it on all my machines.

Changing your BASH prompt

You change your BASH prompt by editing a file in your home directory called .bashrc. I’ll use nano in this example to edit the file, but you can use whatever editor you’re comfortable with.

nano ~/.bashrc

You may see a section in there like the following:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

This is what is setting your current BASH prompt in most cases. You can comment all this out if you wish, or you can do like I do and just go down to the bottom of the file and add a new PS1 line.

First things first, we need to create what the prompt will look like. Go to bashrcgenerator or EZPrompt and use the drag-and-drop interface to design a prompt you like. Alternatively, you can likely find tons of examples online for PS1 that you can nab.

Once you’re at the bottom of the file, add the PS1 line you got from your preferred source. Save the file with ctrl-x and then ctrl-o (if using nano) and then load another terminal emulator. Your new BASH prompt should be there.

Here is my PS1 line in case you want to see what it looks like in your environment.

PS1="[\[$(tput sgr0)\]\[\033[38;5;6m\]\h\[$(tput sgr0)\]\[\033[38;5;15m\]] [\[$(tput sgr0)\]\[\033[38;5;14m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]] : \[$(tput sgr0)\]"

More resources