HomeBlogsmanzalone's blogMy favorite ways to use drush

My favorite ways to use drush

Drush is by far my favorite tool when it comes to working with Drupal. While graphical tools are often easier to use initially, command-line tools more often give you more power and control. The drush project is an active Drupal project with a major release (3.x) in the works. While it does change some of the basic command names, it organizes and restructures the design to make it easier to extend. The new release also introduces new features/commands, some of which were prior add-ons.

My Favorite/Most Used Commands

Drush provides a number of commands that permit you do perform drupal installation, maintenance, and status operations. Among my most frequently used drush commands/operations:

  1. View the update status of modules
  2. Update site modules
  3. Clearing caches
  4. Download drush modules
  5. Enabling modules
  6. Disabling modules
  7. Download drush to create a new installation
  8. Get the list of enabled (disabled) modules
  9. Get the list of and status of a specific module

In Drush v2.x, I would do this by:

  1. drush -n update
  2. drush update
  3. drush clear cache
  4. drush download m1 m2 m3
  5. drush enable m1 m2 m3 (I often use the -y option in order to skip the confirmation)
  6. drush disable m1 m2 m3 (I often use the -y option in order to skip the confirmation)
  7. drush download (followed by renaming the drupal-N.nn directory to a more meaningful name)
  8. drush statusmodule | grep 'Enabled' (or 'Disabled')
  9. drush statusmodule | grep 'my guess at module name'

Now, with the formal release of drush v3.x. The revised commands for the above are:

  1. drush -n pm-update
  2. drush pm-update
  3. drush cache-clear all (all, theme, menu, css+js are the available options)
  4. drush pm-download m1 m2 m3
  5. drush pm-enable m1 m2 m3
  6. drush pm-disable m1 m2 m3
  7. drush pm-download --drupal-project-rename=my.sitename drupal
  8. drush pm-list --type=module --status=enabled
  9. drush pm-list --type=module --package="Package Name" (if you know the exact package name) ordrush pm-list --type=module | grep 'part of package name or module name' (if you are not sure of a package or module name)

You may notice that I show the full commands instead of the aliases. Many of the command aliases are still the same between v2.x and v3.x. In v3.x they also revised the command names to not contain any spaces. It is interesting to note the full commands as they indicate the types of actions. In this case, pm-, which indicates these are all package manager related commands. The naming structure relates to file and function naming. The aliases for the above are:

  • pm-update: up
  • cache-clear: cc
  • pm-download: dl
  • pm-enable: en
  • pm-disable: dis
  • pm-list: sm

Creating new commands and extensions in v3.x is pretty straight forward. Using the example.drush.inc file as a starting point, I was able to get a test command up and functional within 5 minutes. Many kudos to the designers/maintainers for making things so easy.

Other commands

  • Themes

    While drush v2 and v3 will download themes, drush v2 required add-on that permits you to perform actions on themes. In v3.x this functionality is integrated into drush. Comparing the v2 and v3 comands:

    theme-enable => pm-enable
    theme-disable => pm-disable
    theme-info => pm-info
    theme-list => pm-list --type=theme
    theme-list-enabled => pm-list --type=theme --status=enabled
    theme-set-default => vset theme_default (vset = variable-set)
    theme-set-admin => vset admin_theme (vset = variable-set)
    theme-status => core-status theme (shows the settings for the default and admin themes)

New to Drush v3.x

Renaming the drupal directory

With v2, I always found it frustrating that I had to download drupal, then manually rename the drupal directory. I ended up adding the step to one of my setup shell scripts. Fortunately, v3.x now offers this feature:

drush pm-download --drupal-project-rename='myDrupalDirectoryName'<br />

Limitations, Workarounds and Future Functionality

There are few distinct limitations to drush. This is by no means a criticism of drush--drush is a great, time saving tool. I cringe at the thought of going back to manual installation of packages and the tedious task of navigating the admin pages to perform the various actions. However, there are a few things drush does not do (yet at least). Creating the database for your new siteI've always found it frustrating that you can build your site using drush, but you cannot create the initial database. You either have to go into your mysql instance using phpmyadmin or use mysql from the command line. Some of that is changing as drush matures and additional features are added, but there is one security aspect that I am not sure if drush can address and that is passwords.

Drupal database passwords can already be found in settings.php files. However, that does not expose your instance's admin user passwords. When you create a new database, user, and/or password, you must use login credentials for your instance's admin user. PHP does not provide for cli input of a password so, you the back-end drush processing cannot prompt for it without it appearing on your screen. Yes, you can put it in files, but that is not the way I would like to protect my admin passwords. You can do this from a *nix (includes Mac) shell script or via system calls from PHP on an *nix platform, but drush has tried hard to be platform independent and support the Windows environments as well.

I would like this to be within drupal, but if it can't be platform independent, I am not sure if it should. So, my solution is to have my own shell script to do this. Site InitializationYou created your database. You downloaded drupal and renamed it to your site's directory name. Now, you have to copy the default.settings.php file to settings.php file so that the site is ready for initialization. Then, you need to launch the site and go through the first three pages/forms (choose install language, provide database information, provide basic site information).

I would like to do this from drush. Drush v3.0 added the command site-install:

site-install --db-url=mysql://db_admin:db_pass@localhost:port/dbname --account-user=uname <br /> --account-pass=upass --account-mail=uname@mydomain.com --site-name='My Site Name'I tried to use this, but was using drupal 6 and got the message, "Command site-install requires Drupal core version 7 to run."

So, I will keep using my shell script for now and have the manual step to launch the site and go through those first few menus.

File Ownership - owner:group

With some installations, the owner:group for the web directories is www-data:www:data. When we use drush from some users the drupal directories and files have the owner:group set to 1080:1080. This sometimes causes problems, so we change this (sudo chown -R www-data:www-data drupaldir).


Posted On: December 21, 2010
Posted By: Anonymous


Your concerns regarding database creation and passwords are alleviated when using aegir.

The project page is http://community.aegirproject.org/notebook

Posted On: November 11, 2010
Posted By: Anonymous

Drush Site Install 6

Someone made this after this article was written:



Posted On: September 29, 2010
Posted By: Anonymous

Wonderful Post!

I refer to this post almost every time I am drushing. I would love to see a complete Drush v3.0 command list laid out like this.

I would also love to be able to set Drupal permissions via drush. I have nearly 40 Drupal sites I support and when I find a need to add a module I drush out and make it so. Then I go into EVERY site and manually set the appropriate permissions. I am with you that this is in no way a criticism of drush but a testimony to my enduring laziness.

Thanks again for this post.


Post new comment

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.