Creating Custom Drush Commands

Creating a new Drush command is very easy. Follow these simple steps:

  1. Copy the example commandfile at lib/Drush/Commands/examples/Commands/SandwichCommands.php to mymodule/src/Drush/Commands/MyModuleCommands.php
  2. Edit the namespace and classnames in your file to match the file's location.
  3. Use the classes for the core Drush commands at /lib/Drush/Commands as inspiration and documentation.
  4. Rename and edit the makeSandwich() method. Carefully add/edit/remove annotations above the method and put your logic inside the method.

Drush searches for commandfiles in the following locations:

  • Folders listed in the 'include' option (see drush topic docs-configuration).
  • The system-wide Drush commands folder, e.g. /usr/share/drush/commands
  • The ".drush" folder in the user's HOME folder.
  • /drush and /sites/all/drush in the current Drupal installation
  • All enabled modules in the current Drupal installation
  • Folders and files containing other versions of Drush in their names will be *skipped* (e.g. or drush4/ Names containing the current version of Drush (e.g. will be loaded.