Drush commands reference

drush 同时被 2 个专栏收录
1 篇文章 0 订阅
18 篇文章 0 订阅

Run drush help [command] to view command-specific help.


drush dl cck zen Download CCK module and Zen theme.
drush --uri=http://example.com status Show status command for the example.com multi-site.
drush help --pipe A space delimited list of commands

For details on command flags(e.g. drush sql-dump --skip-tables-key=common), seehttp://drush.ws/ or drush help command-name


Option Description
-r , --root= Drupal root directory to use (default: current directory)
-l , --uri= URI of the drupal site to use (only needed in multisite environments)
-v, --verbose Display extra information about the command.
-d, --debug Display even more information, including internal messages.
-q, --quiet Hide all output
-y, --yes Assume 'yes' as answer to all prompts
-s, --simulate Simulate all relevant actions (don't actually change the system)
-i, --include A list of paths to search for drush commands
-c, --config Specify a config file to use. See example.drushrc.php
-u, --user Specify a user to login with. May be a name or a number.
-b, --backend Hide all output and return structured data (internal use only).
-p, --pipe Emit a compact representation of the command for scripting.


Command (shortcut in parentheses) Description
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 (updb) Execute the update.php process from the command line
status (st) Provides a birds-eye view of the current Drupal installation, if any.
script Run php script(s).
cache clear (cc) Clear all caches.
watchdog show (ws) Shows recent watchdog log messages. Optionally filter for a specific type.
watchdog delete (wd) 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.
enable (en) Enable one or more modules.
disable (dis) Disable one or more modules.
pm-uninstall Uninstall one or more modules.
statusmodules (sm) Show module enabled/disabled status
refresh (rf) Refresh update status information
updatecode (upc) Update your project code
update (up) 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 (sqlq) 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.
vget %var List of all variable names beginning with %var and their values.
vset %var %val Set all variables beginning with %var and set to %val.

Plug-in commands (provided by modules)

Delete all

delete-all article Delect all article nodes.
delete-all all Delete nodes of all types.
delete-all --reset Delete nodes of all types, and reset node, revision and comment counters.
delete-all users Delete users.


devel-download Downloads the FirePHP library from http://firephp.org/.
devel-reinstall Disable, Uninstall, and Install a list of projects.
fn-hook List implementations of a given hook and explore the source of the selected one.
fn-view Show the source of specified function or method.
devel-token List available tokens

Devel Generate

generate-users Creates users.
generate-taxonomy Creates taxonomy.
generate-vocabs Create vocabularies.
generate-terms Create terms in specified vocabulary.
generate-content Creates content.
generate-menu Creates menus and menu items.

Module Builder

mb Generate the code for a new Drupal module, including file headers and hook implementations.
mbdl Update module_builder hook data.
mb-list List the hooks module_builder knows about.
mb-dochooks Adds comment headers to hooks that need them in the given module.
mb-docparams Adds params... WIP!
mb-debug Debug module builder. Does whatever was needed at the time.

Drush Make

make Makes a drupal site out of a makefile.

Backup and Migrate

bam-backup Backup the site's database with Backup and Migrate.
bam-restore Restore the site's database with Backup and Migrate.
bam-destinations Get a list of available destinations.
bam-sources Get a list of available sources.
bam-profiles Get a list of available settings profiles.
bam-backups Get a list of previously created backup files.

Feed API

feedapi create Creates a feed
feedapi refresh Refreshes a feed
feedapi parse Parses a feed and outputs the result to the stdout
feedapi config Shows the config of a given parser or processor
feedapi refresh Refreshes a feed

Statistics Pro

statspro aliases Presents the aliase count for today.
statspro comments Presents the created comment count for today.
statspro error Presents the errors count for today.
statspro modules Presents the installed module count for today.
statspro nodes Presents the created node count for today.
statspro node_types Presents the existent node type count for today.
statspro pi Presents the page impression count for today.
statspro sessions Presents the sessions count for today.
statspro terms Presents the taxonomy term count for today.
statspro uerror Presents the error presented to authenticated users count for today.
statspro upi Presents the page impression for authenticated users count for today.
statspro users Presents the created user count for today.
statspro uwarning Presents the wrning presented to authenticated user count for today.
statspro warning Presents the warning count for today.


zenophile Creates Zen subthemes quickly and easily.
zen Alias for the "zenophile" command.

Omega Tools

omega-subtheme "New Theme Name" Creates an HTML5 subtheme (new_theme_name) in the default sites/all/themes
omega-subtheme "New Theme Name" html5 Creates an HTML5 subtheme (new_theme_name) in the default sites/all/themes
omega-subtheme "New Theme Name" xhtml Creates an XHTML subtheme (new_theme_name) in the default sites/all/themes
omega-subtheme "New Theme Name" --destination=example.com Creates an HTML5 subtheme (new_theme_name) in the default sites/example.com/themes

Node Export

ne-export Export nodes using Node export.
ne-import Import nodes previously exported with Node export.
node-export Export nodes using Node export.
node-export-export Export nodes using Node export.
node-export-import Import nodes previously exported with Node export.


nids : A list of space-separated node IDs to export.


--file : The filename of the output file. If supplied, the node code will be exported to that file (exported to drupal root), otherwise it will export to stdout.
--format : If supplied, node code will be output using a particular export format, if available. (e.g. serialize)
--status : Filter for 'status'; A boolean value (0 or 1) indicating whether the node is published (visible to non-administrators).
--promote : Filter for 'promote'; A boolean value (0 or 1) indicating whether the node should be displayed on the front page.
--sticky : Filter for 'sticky'; A boolean value (0 or 1) indicating whether the node should be displayed at the top of lists in which it appears.
--translate : Filter for 'translate'; A boolean value (0 or 1) indicating whether the node translation needs to be updated.
--language : Filter for 'language'; The language code (e.g. de or en-US) of this node.
--type : Filter for 'type'; The machine-readable name (e.g. story or page) of the type of this node.
--sql : Filter by SQL (EXPERIMENTAL); An SQL query string that returns nids (e.g. "SELECT nid FROM nodes WHERE nid < 10").
--code : Filter by PHP code (EXPERIMENTAL); PHP code that prints or returns, an array or CSV string of nids (e.g. "custom_get_my_nids();"). Don't include PHP tags.

The most useful drush commands

Here I will try to maintain a drush cheat sheet with the list of drush commands I use most often. Full and short version of commands are used interchangeably.

See main information and status of the site

drush status

Clear the cache

drush cc all

Clear the cache, even if Drupal is broken

drush sql-query "DELETE FROM cache"

sql-query executes sql queries in the database where Drupal is installed.

Download the last recommended release of 2 modules (and their dependencies)

drush dl module1 module2

Download a -dev version of a module

drush dl views-7.x-3.x --package-handler=git_drupalorg

Seems that adding --package-handler=git_drupalorg is not needed anymore.

Download the git HEAD version of a module

Short answer: drush does not do that.
Long answer: See http://drupal.stackexchange.com/q/62934/10086

Enable a module

drush en name_of_module -y

-y skips the confirmation question. Some drush commands may miss the -y part, a workaround for this that always works is putting it before:

drush -y en name_of_module

Newer versions of drush automatically download the module if needed.

Disable a module

drush dis name_of_module

Disable a module, even if Drupal is broken

drush sql-query "UPDATE system SET status='0' WHERE name='module_name'"
drush sql-query "DELETE FROM cache_bootstrap WHERE cid='system_list'"

Source: https://drupal.org/node/157632

Uninstall a module

drush pm-uninstall module_name -y

See if a module is available (or installed, etc.)

drush pm-list | grep module_name

Update a module

drush up module_name

Update Drupal

drush up drupal

Update all contrib modules and Drupal

drush up

Run update.php

drush updb

Delete a field

drush field-delete fieldname

Delete an instance of a field

drush field-delete fieldname --bundle=article

Manually delete a field and all its data (not recommended)

drush sql-query "delete from field_config where field_name='fieldname'"
drush sql-query "delete from field_config_instance where field_name='fieldname'"
drush sql-query "drop table field_data_field_fieldname"
drush sql-query "drop table field_revision_field_fieldname"

Set a password for a user

drush upwd --password="asdf" admin

Block a user

drush user-block joe

Log all users out

drush sql-query 'TRUNCATE TABLE sessions;'

Log out a specific user

drush sql-query 'DELETE FROM sessions WHERE uid = 2;'

Get a one-time login link for the Administrator user

drush uli

Run cron

drush cron

Run Ultimate Cron

drush cron-run

Set a variable

drush vset variable_name 'value'

Get the value of a variable

drush vget variable_name

See last logged events (watchdog)

drush ws

See logged events in real time

drush ws --tail

Run a php script with Drupal bootstrapped

drush scr --uri=domain.com script.php

Use --uri to specify the host name. Use --root to specify the site directory (in cron, for example):

/usr/bin/drush --root=/var/www/drupal scr /var/www/drupal/sites/all/scripts/example.php >>/root/logs/scripts/example_log.txt 2>>/root/logs/scripts/example_errors.txt

Run custom code

drush eval "variable_set('foo', 'bar');"

Repopulate database tables used by menu functions

drush eval "menu_rebuild();"

See https://api.drupal.org/api/drupal/includes!menu.inc/function/menu_rebuild/7

Rescan all code in modules or includes directories, storing the location of each interface or class in the database

drush eval "registry_rebuild();"

Useful when moving installed modules. See http://drupal.stackexchange.com/q/17657/10086
If does not work because Drupal cannot bootstrap, do it that way:

drush dl registry_rebuild
drush rr

Update a Feature with database changes

drush fu feature_name

Revert a Feature, update the database to match the code

drush fr feature_name

Revert all features

drush features-revert-all -y

Useful in deployment scripts.

Open a MySQL console logged in

drush sql-cli

Import a backup of the database

drush sql-cli < dump.sql

Export a backup of the database

drush sql-dump | gzip --stdout > $(date +\%Y-\%M-\%d-\%H-\%M-\%S).sql.gz

Remove all database tables (empty the database)

drush sql-drop

Useful before importing a database backup.

See all drush aliases

drush site-alias

Use an alias

drush @aliasname command

Flush image styles

drush image-flush all

Install Drupal

drush site-install

Delete all content of specific content types

sudo drush generate-content 0 --kill --types=facebook,instagram,tweet

Note that you need Devel and Devel Generate modules.

Generate random content

sudo drush generate-content 20 --types=page

Create a boilerplate for a new module

drush mb my_module menu cron --write --name="My module"

  • 0
  • 0
  • 1
  • 一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
钱包余额 0