"drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt."
The drupal project page of drush
The official site of the project is http://drush.ws
with version 4.5 the latest stable release and 5.x under development.
With the tremendous UX improvements in the drupal 7 admin interface you might ask why would I want to use a command line tool? Well, firstly drush can not do everything. For instance, managing nodes (adding, editing, deleting) with drush is not currently supported. However, for many tasks, drush offers several advantages over the GUI. These are:
- speed
- power
- custom scripting - repeatability of tasks
- easy aliased multisite support
The biggest reasons to use drush are its speed and power. To download and enable the
views module for example, you would run the drush commands:
drush pm-download views
drush pm-enable views
These two lines first call the project manager (pm) download method followed
by the enable method. There are also shorthand versions of most commands. So the following is equivalent:
drush dl views
drush en views
With drush, you do not have the overhead of running requests through a browser, or going between pages of the
admin interface. The time savings can significantly add up.
Other pm commands
Shortcut in brackets.
pm-disable (dis)
pm-list //list projects and their statuses
pm-uninstall //uninstall a project
pm-disable (dis) //disable a project
pm-info //Release information for a project
pm-statusmodules (sm) //Show module enabled/disabled status
pm-refresh (rf) //Refresh update status information
pm-updatecode (upc) //update project code
updatedb //call update.php
pm-update (up) //implicitly call pm-updatecode and updatedb
Getting help information
drush status //information about drush installationCommands are of the form:
drush [options] <command>Some optional arguments are:
-v verbose
-d debug
-y answer yes to all prompts
-s simulate
-u user to login with
Help pages:
drush help --pipe space delimited list of commands
drush help | grep "your_search_term"
Keeping drupal up to date
With drush, you can install drupal:
drush dl drupal-7
drush site-install
or upgrade between major versions:
drupal site-upgrade
or stay up to date with minor core version changes, module and theme updates:
drupal update -y
Keeping drush up to date
drush self-update
Backing up and using the watchdog
drush bam-backup //backup
drush watchdog-show (ws) //show recent watchdog messages
drush watchdog-delete (wd-del) //delete watchdog messages
drush watchdog-list //show available types and levels
#list php warnings in the watchdog
drush ws --type=php --severity=warning
Querying the database
drush sql-query "SELECT type FROM node GROUP BY type"
drush sql-query "SELECT nid, type, title FROM node ORDER BY type, title" > nodes.txt
drush sql-query "SELECT nid, title FROM node WHERE type='audio' ORDER BY title"
Targeting a specific site in a multisite setup
drush site-alias (sa) //list site aliases
#list the enabled modules of a specific site
drush siteA pm-list --status=enabled
#compare two sites enabled modules
diff <(drush siteA pm-list --status=enabled) <(drush siteB pm-list --status=enabled --pipe) | grep '<'
Clearing the cache
drush cc all //clear all caches
drush cc theme //clear theme cache
drush cache-clear (cc) //clear caches (no argument will bring up selection menu)
running cron, manipulating variables, setting up an omega subtheme
drush vset preprocess_css 0 --yes Turn off CSS caching
drush vset preprocess_js 0 --yes Turn off JavaScript caching
drush vget %var List of all variable names beginning with %var and their values
drush vset %var %val Set all variables beginning with %var to %val
drush cron run a cron job
omega-subtheme omega easy subtheme creation
Type:
Drupal

All Articles
Comments
Coach Factory Outlet Shops
Add new comment