Setting aliases in Unix system

Its so handy to execute long commands or series of commands with just a word in Unix systems like Linux, Mac, BSDs, etc. In Bash’s ~/.bashrc you can see a line like

 # ~/.bash_aliases, instead of adding them here directly.
if [ -f ~/.bash_aliases ]; then
 . ~/.bash_aliases

What it says is, you can have a file ~/.bash_aliases in which you can define alias to commands you need to run every once and while.

You can define alias like

# ~/.bash_aliases
alias greproute='rake routes | grep '
alias myshortcut='cd ~/projects/myproject && bundle exec rails c'

Solution 2

If you wished not to update the .bash_aliases file, you can have those lines defined in .bashrc file itself.

Note: The above mentioned commands/procedure is not gonna work for shells other than Bourne Again Shell(Bash).

For ZShell users

Open your ~/zshrc file in nano editor or any and paste the following line.

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

Make sure, you have followed the instruction illustrated above to define aliases and have ~/.bashaliases

This works because syntax for bash and zsh are almost same.

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