Bash is configurable software, and you can tweak a lot of its behavior by editing a file in your home directory called .bashrc. To edit, just:

nano ~/.bashrc

On a stock Raspbian installation, you should see something like the following:

Have a look around this file. Much of it may seem like gibberish, but the basics are fairly simple. Lines starting with # are comments. Variables are set like FOO=bar.

Once you've made any changes, you can get them to take effect in your current shell with:

source ~/.bashrc

Write Aliases For Commands You Use Frequently

An alias is just a shortcut you can type in place of another command. You define one like so:

alias moo="cowsay moo"

You can try this at the prompt:

The syntax for adding an alias to .bashrc so that it'll be available on every login is identical - have a look through the stock version of the file and you'll probably find several.

Customize Your Prompt

Your prompt - the bit of text, like pi@raspberrypi ~ $, that appears before your cursor in Bash - is actually defined by a variable called PS1. You can inspect the current value of this variable like so:

pi@raspberrypi ~ $ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\]

Not exactly pretty, is it? It makes use of special escapes like \u for user, \h for hostname, \w for working directory, etc. Sequences like \[\033[01;32m\] are used for special non-printing characters that the terminal recognizes as instructions to  use certain text colors.

Serious prompt customization is outside the scope of this guide, but you can learn plenty by messing around with it. Have a look at ezprompt.net for a quick way to assemble a custom prompt, and see the Bash Reference Manual's Controlling the Prompt section for a breakdown of escape sequences.

Keep More History

The default .bashrc sets history length to 1000. If you're anything like me, your memory needs way more help than that. Look for HISTSIZE (the amount of history kept in memory when Bash is running) and HISTFILESIZE (the amount of history kept in the history file on disk) and adjust them to your liking. Mine look like so:

export HISTSIZE=10000
export HISTFILESIZE=120000

You can look at the contents of command line history with nano $HISTFILE.

This guide was first published on Feb 24, 2015. It was last updated on Feb 24, 2015.

This page (Customize your .bashrc) was last updated on Feb 20, 2015.

Text editor powered by tinymce.