Home > Linux, Tips and Tricks > Linux Bash Aliases

Linux Bash Aliases

If you are constantly typing lengthy commands or a series of common commands, the bash alias feature in Linux is your friend. You can slim down the lengthy bash command into your favorite command name and use it whenever you need.

One of the main advantage is that you can store all your command aliases into a file and carry it with you anywhere. Just plop in the file int the system you are working and you are ready to go. It gets even better if you sync your aliases file to the cloud. So you can add and modify aliases and as long as the bashrc in your profile is pointing to this file, your are good.


Create your bash_aliases file and store it in a place where you like. I typically store it in my desktop.

touch /home/naveen/Desktop/bash_aliases

Add the first command alias to your file – i use these commands to update my system

  1. sudo apt-get update
  2. sudo apt get upgrade
  3. sudo apt-get autoclean
  4. sudo apt-get autoremove

Now you can combine all 4 commands to 1 alias. Put the below line into the alias file

alias system_update="sudo apt-get update; sudo apt get upgrade; sudo apt-get autoclean; sudo apt-get autoremove"

system_update is your alias for all the 4 commands.

Final step is to tell bashrc to use our aliases file

There is a .bashrc file located at your home directory – its hidden ( press CTRL+H). Open it up and search for these lines

if [ -f ~/.bash_aliases ]; then
 . ~/.bash_aliases

If you cannot find these lines, then add them to the file at the bottom.

Basically we are instructing bashrc that if it can find the file called .bash_aliases in our home directory, use that.

All we need to do now is create a symbolic link to the bash_aliases file on our desktop

The symbolic link will be called .bash_aliases and we will place it in our home directory.

cd /home/naveen
ln -s /home/naveen/Desktop/bash_aliases .bash_aliases
  • Note that you can directly put all your commands into the file called .bash_aliases and put it in your home directory ( no need to create symlinks )
  • You can also just change the file path in the if condition

Log out and log in

Open a terminal and issue the command system_update

You can carry the file on your desktop with you and make a symlink to in any other system



Categories: Linux, Tips and Tricks
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: