How do I use drush?

To use drush, first login to your web server via SSH (see the 'See also' links at the bottom of this FAQ). Once in, the first command you can try is simply:

$ drush

You should see a list of possible commands. One of the key commands to be aware of is this:

$ drush sa

This will give you a list of available aliases. An alias is a way to run drush against a specific website available on the server. We always create aliases for your sites (assuming we set them up) so you can use those aliases to execute commands against a specific site. Let's have a look at an imaginary response from `drush sa`:

$ drush sa
@examplecom_prod
@examplecom_stage
@foobar_stage

So by way of an example, to clear all Drupal caches on the site represented by the alias `@foobar_stage` one would use this command:

$ drush @foobar_stage cc all

If you do not actually have any aliases set up then all your Drupal websites will be in the /var/www directory on the server. To use drush without aliases, you simply have to switch to the appropriate directory before running the command. Continuing our example, to see the available websites run this command:

$ ls -l /var/www
total 5
drwxr-xr-x  2 root     www-data 4096 Mar 13  2013 html
lrwxrwxrwx  1 root     www-data 34 Oct 10 00:14 live.example.prod
lrwxrwxrwx  1 root     www-data 30 Oct 10 00:14 live.example.stage
lrwxrwxrwx  1 root     www-data 28 Oct 10 00:14 live.foobar.stage
drwxr-xr-x 13 root     www-data 4096 Oct  8 16:57 shared

If you use our Jenkins continuous integration, you might see many more entries than this, but the key ones are prefixed with 'live.' always, so you can narrow your list to the available live sites like so:

$ ls -l /var/www/live.*

Once you've identified the site you want to use drush against, switch directory to the 'www' root of that site and then run drush as usual. For example, using the foobar project and the stage branch again, let's clear the cache:

$ cd /var/www/live.foobar.stage/www
$ drush cc all
Many Drupal modules provide additional drush support, so when you install a new Drupal module it is always worth executing the drush command to see if there are any new options available.

Here is an excellent website for listing what modules provide what drush commands for Drupal 7:

http://drushcommands.com/

And this is the main website for drush documentation, which lists all the 'core' commands and how to use them:

http://www.drush.org/

It is worth noting, different drush versions have different commands. You can check your current drush version with this command:

$ drush --version
drush version 5.8