Customize Terminal Prompt

Customize your terminal prompt add a little color and output more information by default.

In order to do this we need to edit your .bashrc file which is hidden in your home directory. First let’s back up your current .bashrc file just in case something goes wrong or in the future you would like to change it back.

To back up the .bashrc file simply type:

# cp .bashrc .bashrc.bak

now we need to edit the file using nano.

# nano .bashrc

Delete all the text that is inside the .bashrc and replace it with:

#
# ~/.bashrc
#
export PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"'
# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='\[\e[0m\]\[\e[48;5;236m\]\[\e[38;5;105m\]\u\[\e[38;5;105m\]@\[\e[38;5;105m\]\h\[\e[38;5;105m\] \[\e[38;5;221m\]\w\[\e[38;5;221m\]\[\e[38;5;105m\]\[\e[0m\]\[\e[38;5;236m\]\342\226\214\342\226\214\342\226\214\[\e[0m\]'

ctrl+x then save the file

Or simply download it from Here and copy it to your home directory. Close the terminal, then reopen it.

Terminal after the .bashrc has been edited.

user_terminal_after

Now let’s do the same for the root account.

switch to the root account with:

# su

Enter root password.

Then switch to the root home directory with:

# cd /root

Again we need to back up the .bashrc just in case. To complete this run:

# cp .bashrc .bashrc.bak

Then

# nano .bashrc

Delete all the text that is inside the .bashrc and replace it with:

export PROMPT_COMMAND='echo -ne "\033]0;$PWD\007"'
# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'

PROMPT_COMMAND='history -a;echo -en "\033[m\033[38;5;2m"$(( $(sed -nu "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo)/1024))"\033[38;5;22m/"$(($(sed -nu "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo)/1024 ))MB"\t\033[m\033[38;5;55m$(< /proc/loadavg)\033[m"' PS1='\[\e[m\n\e[1;30m\][$$:$PPID \j:\!\[\e[1;30m\]]\[\e[0;36m\] \T \d \[\e[1;30m\][\[\e[1;34m\]\u@\H\[\e[1;30m\]:\[\e[0;37m\]${SSH_TTY} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] \[\e[1;37m\]\w\[\e[0;37m\] \n($SHLVL:\!)\$ '

ctrl+x then save the file

Or simply download it from Here and copy it in to your root home directory. Close the terminal, then reopen it.

Terminal after the .bashrc has been edited.

root_terminal_after

That’s it this is how we change the terminal prompt.

If at any point you wish to change the prompt back to default simply run:

# cp .bashrc.bak .bashrc

This will copy back the original file and restore your prompt back to default.

Thank you for reading.