Drush - Drupal Shell utility

Last modified: November 11, 2009 - 18:00

Drush is a command line Unix scripting interface for interacting with Drupal. It makes everyday site administration and repetitive development tasks faster and easier. It is not, however, a module, and does not install like one either, so pay attention to the installation instructions found in the project's README file.

Like most arcane command line utilities, Drush becomes incredibly powerful and useful to you only after you gain an understanding of what it can do. Most people don't comprehend what Drush is capable of because they've never downloaded it and played around with it. Take a look at a copy of the current help text below which outlines some of the many tasks that Drush can automate for you -- the same thing you'd see by typing "drush help" into the command line -- and you'll begin to see why you need to be using this amazing set of shell scripts for all your Drupal site tasks:

Available Drush Commands:

help
Print this help message. Use --filter to limit command list to one command file (e.g. --filter=pm)
cron
Run all cron hooks.
updatedb
Execute the update.php process from the command line
status
Provides a birds-eye view of the current Drupal installation, if any.
cache clear
Clear all caches.
watchdog show
Shows recent watchdog log messages. Optionally filter for a specific type.
watchdog delete
Delete all messages or only those of a specified type.
sync
Rsync the Drupal tree to/from another server using ssh.
eval
Evaluate arbitrary php code after bootstrapping Drupal.
script
Runs the given php script(s) after a full Drupal bootstrap. NOTE: you can't supply absolute paths to the script e.g. ~/Desktop/script.php won't work Desktop/script.php will
enable
Enable one or more modules.
disable
Disable one or more modules.
uninstall
Uninstall one or more modules.
statusmodules
Show module enabled/disabled status
refresh
Refresh update status information
updatecode
Update your project code. Moves existing project files to the backup directory specified in the config.
update
Update your project code and apply any database updates required (update.php)
info
Release information for a project
dl
Download core Drupal and projects like CCK, Zen, etc.
test mail
Run all tests and mail the results to your team.
test clean
Delete leftover tables and files from prior test runs.
sql conf
Print database connection details.
sql connect
A string for connecting to the DB.
sql dump
Exports the Drupal DB as SQL using mysqldump.
sql query
Execute a query against the site database.
sql load
Copy source database to target database.
sql cli
Open a SQL command-line interface using Drupal’s credentials.

Even more in depth command-specific help is available by typing drush help {command} but hopefully the above list will give you a taste of what is possible with Drush.

Extensions

Other modules provide new drush commands! These become available automatically and are listed when you run drush help. The extension module does not need to be enabled.

Tips

Drush autodetects the appropriate site from directory context, and read its configs from there, so if your command shell is in {drupaldir}/sites/all or anywhere under {drupaldir} then drush commands will apply to your default install. If you move your shell session into {drupaldir}/sites/mysite, then drush commands will be run in the context of the mysite multisite instance. You can always run drush status to check the currently active context.

Example Commands

drush dl cck zen
Download current recommended versions of CCK module and Zen theme.
drush enable content
Enable the content (cck) module.
drush --uri=http://example.com status
Show status command for the example.com multi-site.
drush info backup_migrate
Get info on all available releases for backup_migrate.module, e.g.
Project         Release      Date       
backup_migrate  6.x-2.x-dev  2009-Apr-07
backup_migrate  6.x-1.2      2009-Jan-18
backup_migrate  6.x-1.0      2008-Aug-14
backup_migrate  6.x-1.x-dev  2009-Feb-19
drush -v  dl backup_migrate-6.x-1 --package-handler=cvs
Checkout via CVS, the current stable version of the backup_migrate module on the DRUPAL-6--1 branch into your sites/{active.site}/modules/ directory. In this case the result is identical with just drush dl backup_migrate --package-handler=cvs as the requested version is the recommended version.
drush -v  dl backup_migrate-6.x-2.x-dev --package-handler=cvs
Checkout via CVS, the unstable dev version of the backup_migrate module on the DRUPAL-6--2 branch into your sites/{active.site}/modules/ directory.
drush -v  dl backup_migrate-6.x-2.x-dev
Without specifying a --package-handler, (the default) the project bundle is retrieved via wget, and unpacked locally without the CVS information. This may overwrite any local changes.

See also: Offsite blog tutorial (with pictures) on Installing and running drush on OSX by morten

note: "drush enable cck"

chachasikes - October 5, 2009 - 16:34

note:
"drush enable cck" doesn't work
"drush enable content" *does* work

i think you have to use the real module name, not the module package name.

chacha

You can correct the

throk - October 6, 2009 - 17:28

You can correct the documentation. You can just click on the edit tab at the top. I would change it for you, but I haven't used Drush yet, i'm "just looking" for now and don't know whether you're actually right.

__________________________________________________________
http://throk.net | @throk

Could someone add "drush

stodge - October 28, 2009 - 14:19

Could someone add "drush provision" as I have no idea what it does.

Thanks

Update command

shanesj - November 17, 2009 - 17:57

If you want to exclude a module from the update command, you will need to disable the module prior to running update and then re-enable the module after the update is done. If there is another way I would love to know how.

www.withwarranty.com
Selling your car? Sell it Faster! ForSaleWithWarranty.com

"All tyranny needs to gain a foothold is for people of good conscience to remain silent."
Thomas Jefferson

Update Selectively

TravisCarden - November 21, 2009 - 03:59

You can selectively update modules by specifying as parameters which ones you want affected:

drush update cck views globalredirect pathauto

I don't know of any way to exclude modules, but this, at least, is something.

 
 

Drupal is a registered trademark of Dries Buytaert.