How to customize your terminal command prompt

####Background
My system is a single user so I really didn’t need a reminder of who was logged in, nor onto which machine.

The original terminal prompt pfeiffep@pfeiffep-Studio-1749:~$ is rather long and not terribly useful to me, so I changed it to 12:58 PM:~$

current time : ~current directory $ indicates normal user prompt

Testing a new command prompt is straight forward and should be done prior to making it permanent. The default Ubuntu install uses BASH which is an acronym for __B__ourne __A__gain __SH__ell. A shell is a command language interpreter whose purpose is to provide an interface between the you and the kernel.

BASH command prompt is composed in a file named .bashrc with variables. The main variable is PS1. In a terminal using command echo $PS1 will display a line that won’t look like your command prompt at all! ${debian_chroot:+($debian_chroot)}\u@\h:\w\$

####The safe method to test all this####
in a terminal enter
ORIG=$PS1 … saves current prompt
PS1='\@:\w\$' … changes prompt to 12:58 PM:~$
PS1=$ORIG… returns your original prompt

Many options are available for you to customize and adding color

https://linuxconfig.org/bash-prompt-basics#h3-bash-prompt-special-characters
https://help.ubuntu.com/community/CustomizingBashPrompt

None of the above changes are permanent - next login will return everything to original state.

After experimenting and customizing your command prompt to satisfaction you will need to make in permanent.

####Making your choice permanent####
The change requires editing of .bashrc
I suggest entering a second terminal to make changes to .bashrc - this provides an easy & accurate method to obtain the exact PS1 content

#####in another terminal enter#####
cp .bashrc .bashrc.bu … makes a backup of your current file
pluma .bashrc
scroll to the section below - starts at line 59 on my machine

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

copy the line between else and fi

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

enter a new line by hitting return with your cursor prior ti fi
enter a # before line starting PS1
enter your new prompt definition [the below example is from MY choice]

else
#PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\w$ ’
PS1=’${debian_chroot:+($debian_chroot)}@:\w$ ’
fi

I strongly suggest changing ONLY the characters following }

Save the file; the next login will result in your chosen command prompt.

Login doesn’t require a reboot - add the Log Out Button to the top panel. Right Click top panel,>add to panel>log out

####Change your mind?####
You made a copy of the original file so no editing is required here.
In a terminal enter
cp .bashrc.bu .bashrc

Next login will return your original command prompt

3 Likes