Drush: The Swiss Army Knife for Drupal
Article
By now, if you have been using Drush for a while I assume you are comfortable with all the basics. (I consider the basics to be things like downloading modules or updating a site.) I also assume you are aware that Drush has plenty of other features built in, but you probably don't take advantage of them. In this article I want to show you a few things that are just as easy to use as the “basics” and only require a little upfront setup to use them. Once you learn them, they will quickly find their way into your daily workflow.
Shell Aliases
Consider how much time you spend typing out commands. Now think of all the commands you type over and over again. Next, think about all the commands that have a lot of options and how often you refer to help resources to remember which options you need to use. Wouldn’t it be better if we simplified those things? Conveniently, Drush allows you to do exactly that: create shortcuts or aliases in a file called drushrc.php
. I'll refer to it as the command file later in this article.
Let's start with an easy example: the clear cache command. This command isn't very long but we can still improve on it. Plus, it's probably one of the most frequently used.
Edit your drushrc.php
file; if it doesn't exist create it. It's typically in your home folder at:
~/.drush/drushrc.php
Add this line to the bottom of this file and save it:
$options['shell-aliases']['ca'] = 'cache-clear all';
We just added a shell alias. Now instead of typing this:
$ drush clear-cache all
You only need to type:
$ drush ca
That wasn't too hard, right? That was one line of code, and you just improved on an already very simple command.