Customizing your .bashrc File

Posted on April 18th, 2014

The ~/.bashrc file is the one that determines the behavior of your Linux shell. The amount of customization you can add to it to personalize your shell is vast, but it is hard to start when you are unsure what kind of customization your are able to add!

To begin editing your .bashrc, type the following command:

sudo gedit ~/.bashrc
Below I have added a bunch of lines you can add and modify to your .bashrc file, with comments included. In general, some of the most useful things you can do in your .bashrc is adding aliases and functions. An alias is simply a keyboard shortcut for a specific bash command. Instead of having to type out a long sequence, you can make an alias to shorten the command. A function is similar, except as expected, you can pass parameters to it.

# =============================================================== #
# Andrew's Example .bashrc
# =============================================================== #

# Makes the terminal prompt display be red in the format [email protected]
# and it also make the rest of the prompt text white
PS1='\[\e[1;31m\]\u@\h\$\[\e[0m\] '

# Change the terminal title bar to always display the current directory
PROMPT_COMMAND='echo -ne "\e]0;$(pwd -P)\a"'


# Open chromium web browser
alias chrome='chromium-browser'

# Show disk information
alias disk='df -h | grep -e /dev/sd -e Filesystem'

# Show terminal history
alias h='history'

# List current jobs
alias j='jobs -l'

function encode() { echo -n $@ | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg'; }
# Search google by typing 'google argument' where argument is your search
function google() { firefox"`encode $@`" ;}

# Search yahoo
function yahoo() { firefox"`encode $@`" ;}

# Search bing
function bing() { firefox"`encode $@`" ;}

# Search amazon
function amazon() { firefox"`encode $@`" ;}

# Search wikipedia
function wiki() { firefox"`encode $@`" ;}

After you have edited your .bashrc, you will have to restart your terminal for the changes to take effect. Reopen your terminal and try out some of the aliases and functions I have provided. You can see how useful your terminal can be by customizing it yourself. I have seen some people who have even created a weather function to report the current weather based off a zip code! The terminal is an incredibly useful tool in Linux, so why not utilize it more effectively.

comments powered by Disqus
Andrew Backes

A Software Engineer living in Milwaukee, WI. Passionate about web/software development, tech, open source, and gaming.