Blog Roll

The official mumblings of a senile monkey sent from outer space.

Bash Shell Colouring

Thursday, 02 April 2015 15:44 Comments 0

Before you begin this tutorial please ensure you have installed the vim application.

Apply Changes

First you'll need to navigate to your home directory by issuing the following command:

	
	root@beast-nas:~# cd ~
	

Then list the files within this directory:

	
	root@beast-nas:~# ls -la
	

Here you will see a file called .bashrc
We need to edit this file to allow colouring of our files and directories for the SSH console. In order to do this issue the following command:

	
	root@beast-nas:~# vim .bashrc
	

This will open the file .bashrc within the vim text editor. From here we can edit the file.

To edit files within vim you first have to press the "insert" key on your keyboard. This command instructs vim that you wish to edit the file.

Once pressed "-- INSERT --" will display in the bottom-left corner of the screen.

Some notes to consider when using vim:

  • If you tap "insert" a 2nd time, it'll read "-- REPLCE --" instead which mean "Replace" so be careful!
  • For numbers input DO NOT USE THE NUMPAD as the result may be unexpected ("Num Lock" anyone?). Use the keys above the keyboard instead.

If you get stuck editing the file within vim just hit the "Esc" key then hold down the "shift" key and hit ":" and type "q!" and hit "Enter" - this exists the file without saving it

Anyways, once vim is opened you need to un-commend some lines. You do this by removing the hash # from the beginning of the line(s).
Here is the file as it should look when you're done editing:

	
	# ~/.bashrc: executed by bash(1) for non-login shells.

	# Note: PS1 and umask are already set in /etc/profile. You should not
	# need this unless you want different defaults for root.
	# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
	# umask 022

	# You may uncomment the following lines if you want 'ls' to be colorized:
	export LS_OPTIONS='--color=auto'
	eval "`dircolors`"
	alias ls='ls $LS_OPTIONS'
	alias ll='ls $LS_OPTIONS -l'
	alias l='ls $LS_OPTIONS -lA'
	#
	# Some more alias to avoid making mistakes:
	alias rm='rm -i'
	alias cp='cp -i'
	alias mv='mv -i'
	

To exit "edit" mode, just press the "Esc" key on your keyboard. "-- INSERT --" at the bottom-left corner of the screen will disappear.

To save the file hold down the "shift" key and hit the colon key ":"
":" will appear in the bottom left corner of the screen.
Type: "wq!" (without the quotation marks) and hit "Enter".

	
	:wq!
	

vim will save the file and return you to the shell.

Verifying the Changes

To verify your changes run the following command:

	
	root@beast-nas:~# vim .bashrc
	

This will display the file and it's contents should look similar to the image below:

Vim .bashrc display within SSH shell
Fig 1: The ".bashrc" file displayed on the ReadyNAS within an SSH console.

To exit the file without saving hold down the "shift" key and hit the colon key ":"
: will appear in the bottom left corner of the screen.
Type: "q!" (without the quotation marks) and hit "Enter"

Exiting vim without savign changes
Fig 2: Exiting vim without saving changes.
#ReadyNAS