Useful Drush commands

Public

Drush command and their descriptoins

</> CopyGet raw version
text
  1. pm-update --pipe (up --pipe)
  2.  
  3.  
  4. pm-update will go ahead and update your code and run database updates. But there may well be some special requirements when upgrading a particular module that you need to be aware of and simply running pm-update could be dangerous if you don’t check first.
  5.  
  6. So how do you get a list of what it will update first, before actually performing the update? Add the pipe option, and you will then get a nice list.
  7.  
  8. You can then go to the drupal.org project page for each module that needs updating and have a read of the release notes before doing the actual update.
  9.  
  10. Here is an example of what you get after running the command:
  11.  
  12. drupal 7.23 7.26 SECURITY-UPDATE-available backup_migrate 7.x-2.4 7.x-2.8 Update-available backup_migrate_dropbox 7.x-1.0-alpha1+4-dev 7.x-1.0-alpha1 Update-available context 7.x-3.0-beta6 7.x-3.2 SECURITY-UPDATE-available ctools 7.x-1.2 7.x-1.4 SECURITY-UPDATE-available geshifilter 7.x-1.1 7.x-1.2 Update-available google_authorship 7.x-2.0-beta1 7.x-2.0 Update-available hierarchical_select 7.x-3.0-alpha5 7.x-3.0-alpha6 Update-available inline 7.x-1.x-dev 7.x-1.x-dev Update-available libraries 7.x-2.1 7.x-2.2 Update-available markdown 7.x-1.1 7.x-1.2 Update-available metatag 7.x-1.0-beta4 7.x-1.0-beta9 Update-available mollom 7.x-2.7 7.x-2.9 Update-available views 7.x-3.5 7.x-3.7 SECURITY-UPDATE-available xmlsitemap 7.x-2.0-rc2 7.x-2.0 Update-available
  13.  
  14. Thanks to James Oackley for this tip.
  15.  
  16. watchdog-show --tail (ws --tail)
  17.  
  18. Running watchdog-show will return a list of messages from watchdog. You can take this further by viewing messages in real time, as they are being recorded with the tail option.
  19.  
  20. I find this is particularly helpful when debugging. You can add a call to watchdog in your code and with watchdog-show --tail running, see the message appear as you load a new page.
  21.  
  22. If you get a lot of messages appearing, you can isolate messages from your module.
  23.  
  24. First, give your watchdog call a unique type:
  25.  
  26. watchdog('my_unique_type', print_r($variable, true));
  27.  
  28. Then in the command, use the --type option to isolate messages with the name 'my_unique_type':
  29.  
  30. watchdog-show --tail --type=my_unique_type
  31.  
  32. watchdog-show --tail was mentioned by an anonymous commenter.
  33.  
  34. drush archive-dump (ard)
  35.  
  36. drush archive-dump will backup your code, database and files (from the files directory) into a single file.
  37.  
  38. Use the destination option to tell it where to put the backup file. For example:
  39.  
  40. drush ard --destination=/var/www/site/backups/example.tar
  41.  
  42. Thanks Agnar Ødegård and Jean-Francois Bohemier for recommending this command.
  43.  
  44. drush sql-dump > dumpname.sql
  45.  
  46. drush sql-dump will perform a dump of the database. It is similar to what you will get from running mysql-dump.
  47.  
  48. You can save it to a particular location using the result option:
  49.  
  50. drush sql-dump > dumpname.sql --result=/var/www/site/backups/example.sql
  51.  
  52. You can compress the file with the gzip option (a gzip program must be specified in your path):
  53.  
  54. drush sql-dump > dumpname.sql --gzip --result=/var/www/site/backups/example.sql
  55.  
  56. If you don’t want to add the result option in everytime, you can add it to a drushrc.php file:
  57.  
  58. $options['result-file'] = '~/Desktop/@DATABASE/@DATE.sql';
  59.  
  60. Thanks to Agnar Ødegård for suggesting drush sql-dump > dumpname.sql,Mike Raichelson for the —result-file option and Capi Etheriel for the gzip option and drushrc.php.
  61.  
  62. drush sql-cli (sqlc)
  63.  
  64. drush sql-cli will open the sql command-line interface, using the site credentials specified in settings.php.
  65.  
  66. You can also use this command to restore a database dump:
  67. drush sql-cli < dumpname.sql
  68.  
  69. Thanks to Agnar Ødegård for recommending sql-cli.
  70.  
  71. drush sql-sync
  72.  
  73. drush sql-sync will sync your local DB with what’s on the live server.
  74.  
  75. Thanks to Mike Keran for recommending sql-sync. Check out his article onmaking sql-sync safer
  76.  
  77. drush fn-hook (fnh)
  78.  
  79. drush fn-hook will tell you which modules on your site have implemented a specific hook.
  80.  
  81. For example, find which modules implement hook_form_alter:
  82.  
  83. drush fn-hook form_alter
  84.  
  85. This will return a list of modules, like so:
  86.  
  87. Enter the number of the hook implementation you wish to view. [0] : Cancel [1] : block_class [2] : context [3] : inline [4] : metatag [5] : mollom [6] : token
  88.  
  89. Select one to see the modules actual implement of hook_form_alter. After selecting [1] block_class, you will get this:
  90.  
  91. // file: /home/blair/befused/www/sites/all/modules/contrib/block_class/block_class.module, lines 63-78
  92.  
  93. /**
  94.  
  95. * Implements hook_form_alter().
  96.  
  97. *
  98.  
  99. * Alter block edit form to add configuration field.
  100.  
  101. */
  102.  
  103. function block_class_form_alter(&$form, &$form_state, $form_id) {
  104.  
  105. if (user_access('administer block classes') && ($form_id == 'block_admin_configure' || $form_id == 'block_add_block_form')) {
  106.  
  107. // Load statically cached block object used to display the form.
  108.  
  109. $block = block_load($form['module']['#value'], $form['delta']['#value']);
  110.  
  111.  
  112. $form['settings']['css_class'] = array(
  113.  
  114. '#type' => 'textfield',
  115.  
  116. '#title' => t('CSS class(es)'),
  117.  
  118. '#default_value' => isset($block->css_class) ? $block->css_class : '',
  119.  
  120. '#description' => t('Customize the styling of this block by adding CSS classes. Separate multiple classes by spaces.'),
  121.  
  122. '#maxlength' => 255,
  123.  
  124. );
  125.  
  126.  
  127. $form['#submit'][] = 'block_class_form_submit';
  128.  
  129. }
  130.  
  131. }
  132.  
  133. Thanks to Mike Keran for this command. As he mentions it is particularly helpful if you suspect a module is implementing a hook which is altering your code.
  134.  
  135. drush user-login (uli)
  136.  
  137. drush user-login will display the one-time login for a particular user. You can use that to quickly login to a site as that user if you need to test something.
  138.  
  139. Thanks to Raph for recommending drush user-login.
  140.  
  141. drush pm-updatecode (upc)
  142.  
  143. I have talked about drush pm-update in my top 10 Drush commands post. This updates module and core code and runs the database updates, all with the one command. But some people prefer to update the code separately to performing the database update. You can do that with drush pm-updatecode. After you have run it, you can check to see what has changed before you touch the database. If your code is under source control, then that is just a matter of running something like git diff before committing.
  144.  
  145. Thanks kiwimind for this tip.
  146.  
  147. drush | grep command or drush --filter=command
  148.  
  149. Most of us don’t have photographic memories, so can’t remember every single Drush command. If you just run the command drush, you will get a list of every drush command available to you. That is a long list, but you can