Setting up a bash alias

In my day-to-day work I am using Vagrant with VirtualBox which provides an easy to setup development environment pre-configured with ubuntu, php, mysql and nginx.

One thing that helps save time is reducing the time spent writing terminal commands, this is where a bash alias comes in handy.

To set one up you need to ssh into the vagrant machine (I use putty on windows), and then type in

vim ~/.bashrc

this opens your bashrc file in the editor vim, to begin editing the file use the insert (ins) key.

As far as I know you can add your alias’s anywhere outside of code blocks in this file, here’s a screenshot of mine

bashrc alias

so as you can see I have set up a couple of commands, this would save me typing php artisan migrate and can simply type migrate. ( alias migrate=”php artisan migrate” )

After typing your aliases in you need to first exit insert mode by pressing Esc, then type :w and hit enter to save your changes and :q should quit vim.

To check our alias works without requiring a machine reboot we need to apply the changes from our .bashrc file, to do this from the terminal type

source ~/.bashrc

Hopefully your alias will work now.

Leave a Reply

Your email address will not be published. Required fields are marked *