Bashrc Linux – a guide

A brief guide to the .bashrc styling file in Linux

All of us who are familiar with Linux may also be familiar with some, or all, of the core Run Commands files which, as the name suggests, run at start up. In this brief article I am going to take a look at the main .bashrc file which is the primary RC file and one in which all of my terminal configurations are set up. The bashrc file is one of the hidden systems files beginning with a dot. You may have two copies of this file on your system. One intended for the general user located in the /home/username directory and with perms set to (-rw-rw-r–) or (664) in octal format and owner (chown) set to user:user. You should also have a copy of the file in the ROOT directory at /root with owner (chown) set to root:root

Bashrc and the Terminal

All Linux users will be familiar with the venerable old terminal in which we do most of our sysadmin tasks and lots of other things depending on ones level of geekdom. I like to run a lot of operations in terminal including AV file work with the FFMPEG utility.

But you may be asking what does this have to do with the .bashrc file? Well, .bashrc is where we setup interesting terminal configurations such as colour coding. I created a particular colour scheme that I like to use on all of my Linux systems from RasPi to video editing behemoths. A full copy of my bashrc cofig file can be copied or downloaded below. NB the .bashrc file should not contain any confidential information or any access paths to your system. It is just a simple universal set of instructions or system commands for general configurations.

My preferred prompt colours

Linux terminal prompts

Terminal prompts for User, Root and SSH connection to server. All three are automatic and set according to specific instructions in the .bashrc file. These are examples from a small HP laptop with the machine name “mini”.

The command prompt is designated as PS1 in the .bashrc script

My PS1 main prompt is configured like this: –

PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;33m\]:\[\033[01;33m\]\w\[\033[00;97m\]\$ ‘

But we are only interested in this part: –

[\033[01;32m\]\u@\h\[\033[01;33m\]:\[\033[01;33m\]\w\[\033[00;97m\]\$ ‘

[01:32m\]\u@h sets the color of the Username @ Host (name) part of the prompt. In my case it is green. 01 sets it to bold and 32 is the color code for green.

[\033[01;33m\]:\[\033[01;33m\]\w\ Sets the color of the separator (colon) and the Working directory. In this case they are both Bold and yellow 01 & 33 respectively.

[\033[00;97m\]\$ Sets the color of the tail symbol ($) and the colour of ‘normal’ text in the terminal. In this case 00 (non bold) and 97 for white.

We have a second PS1 prompt for SSH connections. This will automatically display if the machine is accessed through an SSH connection. piece of code: –

if [[ -n $SSH_CLIENT ]]; then
PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;36m\]\u@\h\-ssh\[\033[00m\]:\[\033[01;33m\]\w\[\033[00m\]\$ ‘

The PS1 this time has color codes for turquoise (36) and yellow (33) etc.

The Root prompt is activated form a duplicate of the .bashrc file in the root directory with root:root ownership. The only difference being that the main PS1 prompt has color values for red instead of green.

File type colours

Colour coding according to file type (extension) is set by the long list of items near the bottom of the .bashrc file known as LS_COLORS. Note that the colour is determined in a particular format. Lets take .mp3 files as an example, you can see that they ‘print’ as turquoise in my setup.

Notice how .mp3=00;96:* the first digit(s) are the attribute code: –

  • 00 none
  • 01 bold
  • 04 underscore
  • 05 blink
  • 07 reverse
  • 08 concealed

If I was to set this to 05 then all of the .mp3 file names would be blinking! The next digit(s) are the actual color code. My terminal is set to display 256 colours and the respective codes can be found here: –

90 Dark grey
91 Light red
92 Light green
93 Yellow
94 Light blue
95 Light purple
96 Turquoise
97 White
100 Dark grey background
101 Light red background
102 Light green background
103 Yellow background
104 Light blue background
105 Light purple background
106 Turquoise background
107 White background

My home folder bashrc file — this is a .txt file – rename to .bashrc to use AT OWN RISK

«   |   »

Category: code, Linux   Tags: , ,


prestbury web


Set up in 2016 by Oliver Wood, Prestburyweb provides support in all aspects of web based media to business & organisations across the UK.


© 2023   Presweb Wordpress theme by Oliver Wood