How to add aliases to .bashrc

Often, when using linux, there are times when you need to re-use a long-winded command on a regular basis. Wouldnt it be nice if you could configure your system to carry out that command with just a simple keyword commmand?

Well luckily for us, we can. let me give you an example. The command i use if i want to watch a video within the framebuffer (ouside of X) is as follows:

sudo mplayer -vo fbdev -fs -vf scale=800:-3 /name/of/video.avi

There is no way i’m going to remember that everytime i come to watch a video… Now sure, i could save this into a txt file and grab it when i need it, or even write a script to handle it, but there is a more elegant way. Use an alias.

An alias is just like giving your own unique name to a command for simplicity. I want my alias to be ‘clivid’ so that i can type ‘clivid /path/to/video.avi’ and the computer will do – ‘sudo mplayer -vo fbdev -fs -vf scale=800:-3 /path/to/video.avi’

Heres what you do: open a terminal emu, type

sudo leafpad ~/.bashrc

Or whatever txt editor you use if you dont like leafpad.

You will be confronted with your .bashrc file. Scroll to the very bottom, this is where we will add the alias

First add a comment so you know what the alias does my case its:

#Alias for opening mplayer within framebuffer

Next is the line which actually adds the alias

alias clivid='sudo mplayer -vo fbdev -fs -vf scale=800:-3'

its that simple. You type alias nameOfAlias=’bashCommand’

Save the document, and you’re almost finished. You must recompile .bashrc, type:

source ~/.bashrc

Now test out your new alias on the command line – good luck!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: