Drush — The Drupal Command Line
Drush (Drupal Shell) is the command-line tool for Drupal: clear caches, manage modules, run database, config-sync and deploy tasks. Supports Drupal 8 to 11.
Drush — short for Drupal Shell — is the command-line tool that lets you drive a Drupal installation without clicking through the admin interface. Clearing caches, enabling modules, syncing configuration between environments, running database updates or kicking off a full deployment – you handle it all with short, scriptable commands. Drush supports current Drupal versions 8 through 11 and has become an everyday staple of Drupal development and operations. This guide walks you through the commands that matter most, from a status check to a production deploy.
Core & Info
drush --version — Show the installed Drush version.
drush --versiondrush status — Show the Drupal site status: root, URI, database, PHP version, Drush version, etc.
drush statusdrush status --fields=drupal-version,db-status — Show only specific status fields.
drush status --fields=drupal-version,db-statusdrush list — List all available Drush commands.
drush listdrush list --filter=<group> — List commands in a specific group (e.g. cache, config, pm, sql, user).
drush list --filter=configdrush help <command> — Show help and all options for a specific Drush command.
drush help config:exportdrush core:requirements — Show Drupal's status report (same as admin/reports/status). Lists any site issues.
drush core:requirementsdrush core:edit — Open the active services.yml file in your default editor.
drush core:editCache
drush cache:rebuild — Rebuild all caches. The Drupal 8+ equivalent of cache-clear all. Alias: cr
drush cache:rebuilddrush cr — Alias for cache:rebuild. The most commonly used Drush command.
drush crdrush cache:clear <bin> — Clear a specific cache bin (e.g. render, page, menu, css_js, theme, token).
drush cache:clear renderdrush cache:get <cid> <bin> — Fetch and display a specific cache item by its cache ID.
drush cache:get my_module.data defaultdrush cache:set <cid> <data> <bin> — Cache an arbitrary value into a specific bin.
drush cache:set my_key "hello" defaultConfiguration
drush config:export — Export the active Drupal configuration to the sync directory (config/sync). Alias: cex
drush config:exportdrush cex — Alias for config:export.
drush cexdrush config:import — Import configuration from the sync directory into the active database config. Alias: cim
drush config:importdrush cim — Alias for config:import.
drush cimdrush config:import --partial — Import only the config files present in the sync directory, ignoring missing ones.
drush config:import --partialdrush config:status — Show which configuration items differ between active (DB) and sync (files) directories.
drush config:statusdrush config:diff <name> — Show the diff between active and synced config for a specific config item.
drush config:diff system.sitedrush config:get <name> — Display the full value of a configuration object.
drush config:get system.sitedrush config:get <name> <key> — Get a specific key from a configuration object.
drush config:get system.site namedrush config:set <name> <key> <value> — Set a specific configuration key to a new value.
drush config:set system.site name "My Drupal Site"drush config:delete <name> — Delete a configuration object entirely from the active store.
drush config:delete my_module.settingsdrush config:edit <name> — Open a configuration item in your editor. Changes are saved on exit.
drush config:edit system.performanceModules & Themes (pm)
drush pm:list — List all installed modules and themes with their status. Alias: pml
drush pm:listdrush pm:list --status=enabled — List only enabled modules and themes.
drush pm:list --status=enableddrush pm:list --type=module — List only modules (not themes or profiles).
drush pm:list --type=moduledrush pm:enable <module> — Enable one or more modules. Drush handles dependencies automatically. Alias: en
drush pm:enable views develdrush en <module> — Alias for pm:enable.
drush en admin_toolbardrush pm:uninstall <module> — Uninstall one or more modules and remove their configuration/data. Alias: pmu
drush pm:uninstall develdrush pm:info <module> — Show detailed information about a module or theme.
drush pm:info viewsUpdates & Deploy
drush updatedb — Run any pending database update hooks (from hook_update_N). Alias: updb
drush updatedbdrush updb — Alias for updatedb.
drush updbdrush updatedb --no-post-updates — Run DB updates but skip post-update hooks.
drush updatedb --no-post-updatesdrush deploy — Standard deployment sequence: updatedb, config:import, cache:rebuild, deploy:hook. Use after pulling code.
drush deploydrush deploy:hook — Run all pending hook_deploy_NAME() functions (post-deploy tasks).
drush deploy:hookdrush core:update — Apply any pending Drupal core updates (includes updb, cim, cr).
drush core:updatedrush state:set system.maintenance_mode 1 --input-format=integer && drush cr — Enable maintenance mode and clear cache (before a deployment).
drush state:set system.maintenance_mode 1 --input-format=integer && drush crdrush state:set system.maintenance_mode 0 --input-format=integer && drush cr — Disable maintenance mode and clear cache (after a deployment).
drush state:set system.maintenance_mode 0 --input-format=integer && drush crDatabase
drush sql:cli — Open an interactive SQL shell connected to the Drupal database. Alias: sqlc
drush sql:clidrush sql:query "<query>" — Execute a SQL query directly against the Drupal database. Alias: sqlq
drush sql:query "SELECT uid, name, mail FROM users_field_data LIMIT 10;"drush sql:dump — Export the full Drupal database as a SQL dump to stdout.
drush sql:dump > backup.sqldrush sql:dump --gzip --result-file=<file> — Export the database to a compressed SQL file.
drush sql:dump --gzip --result-file=backup.sqldrush sql:dump --tables-list=<tables> — Dump only specific tables (comma-separated).
drush sql:dump --tables-list=node,node_field_datadrush sql:drop — Drop all tables in the Drupal database. Use with caution!
drush sql:dropdrush sql:sanitize — Sanitize the database by obfuscating emails and resetting passwords. Use on production dumps before sharing.
drush sql:sanitizedrush sql:sanitize --sanitize-password=<pass> — Sanitize and set a specific password for all users.
drush sql:sanitize --sanitize-password=admindrush sql:connect — Print the DB connection string for use with other tools.
drush sql:connectdrush sql:create — Create the database defined in settings.php (if it doesn't exist).
drush sql:createUser Management
drush user:login — Generate a one-time login URL for user 1 (admin). Alias: uli
drush user:logindrush uli — Alias for user:login. Opens a one-time admin login URL.
drush ulidrush user:login --name=<username> — Generate a one-time login URL for a specific user.
drush user:login --name=editordrush user:info <username> — Show information about a specific user account.
drush user:info admindrush user:create <username> --mail=<email> --password=<pass> — Create a new user account.
drush user:create john --mail=john@example.com --password=secretdrush user:password <username> <password> — Set a new password for a user account. Alias: upwd
drush user:password admin newpassword123drush upwd <username> <password> — Alias for user:password.
drush upwd admin admindrush user:block <username> — Block (disable) a user account.
drush user:block spammerdrush user:unblock <username> — Unblock a previously blocked user account.
drush user:unblock johndrush user:cancel <username> — Cancel (delete) a user account.
drush user:cancel olduserdrush user:role:add <role> <username> — Add a role to an existing user.
drush user:role:add editor johndrush user:role:remove <role> <username> — Remove a role from a user.
drush user:role:remove editor johnState & Variables
drush state:get <key> — Get the value of a Drupal state variable.
drush state:get system.cron_lastdrush state:set <key> <value> — Set a Drupal state variable to a new value.
drush state:set system.maintenance_mode 1drush state:delete <key> — Delete a Drupal state variable.
drush state:delete mymodule.custom_flagCron & Queue
drush cron — Run all cron tasks that are due, as defined by each module's hook_cron().
drush crondrush queue:list — List all available queues with their item counts.
drush queue:listdrush queue:run <queue> — Process all items in a specific queue.
drush queue:run mymodule_import_queuedrush queue:run <queue> --items-limit=<n> — Process only a limited number of queue items.
drush queue:run mymodule_import_queue --items-limit=50drush queue:delete <queue> — Delete all items from a specific queue without processing them.
drush queue:delete mymodule_import_queueWatchdog (Logging)
drush watchdog:show — Show recent watchdog log entries. Alias: ws
drush watchdog:showdrush ws — Alias for watchdog:show.
drush wsdrush watchdog:show --count=<n> — Show the last N watchdog entries (default: 10).
drush watchdog:show --count=50drush watchdog:show --severity=<level> — Filter by severity: debug, info, notice, warning, error, critical, alert, emergency.
drush watchdog:show --severity=errordrush watchdog:show --type=<type> — Filter watchdog messages by type (e.g. php, cron, user, system).
drush watchdog:show --type=phpdrush watchdog:show --filter=<string> — Filter watchdog messages containing a specific string.
drush watchdog:show --filter="Access denied"drush watchdog:tail — Follow the watchdog log in real-time (like tail -f). Alias: wt
drush watchdog:taildrush watchdog:delete --severity=<level> — Delete watchdog entries of a specific severity level.
drush watchdog:delete --severity=debugdrush watchdog:delete --all — Delete all watchdog entries.
drush watchdog:delete --allSite Install
drush site:install — Install Drupal using the standard profile. Drops and recreates all tables. Alias: si
drush site:installdrush si <profile> — Install Drupal using a specific installation profile.
drush si minimaldrush site:install --db-url=mysql://user:pass@localhost/dbname — Install Drupal with a specific database connection string.
drush site:install --db-url=mysql://drupal:drupal@localhost/drupaldrush site:install --account-name=<name> --account-pass=<pass> --account-mail=<email> — Set the admin account credentials during installation.
drush site:install --account-name=admin --account-pass=admin --account-mail=admin@example.comdrush site:install --site-name="<name>" --site-mail=<email> — Set the site name and site email during installation.
drush site:install --site-name="My Drupal" --site-mail=info@example.comdrush site:install --existing-config — Install Drupal from existing configuration in the config/sync directory.
drush site:install --existing-configAliases & Multi-site
drush @<alias> <command> — Execute a command on a remote or alternate Drupal site defined by a site alias.
drush @prod cache:rebuilddrush site:alias — Show all defined site aliases.
drush site:aliasdrush sql:sync @<source> @<target> — Copy the database from one site alias to another (e.g. prod to local).
drush sql:sync @prod @selfdrush rsync @<source>:%files/ @<target>:%files/ — Sync files between two site aliases using rsync.
drush rsync @prod:%files/ @self:%files/drush --uri=<uri> <command> — Run a command targeting a specific multisite URI.
drush --uri=sub.example.com cache:rebuilddrush --root=/var/www/drupal <command> — Target a Drupal installation at a specific directory path.
drush --root=/var/www/drupal statusGenerate (Code Generation)
drush generate — List all available code generators.
drush generatedrush generate module — Interactively scaffold a new custom module with all boilerplate files.
drush generate moduledrush generate controller — Generate a Drupal controller class for a module.
drush generate controllerdrush generate service — Generate a Drupal service class and service definition.
drush generate servicedrush generate form — Generate a Drupal form class (ConfigFormBase or FormBase).
drush generate formdrush generate plugin:block — Generate a custom Block plugin class.
drush generate plugin:blockdrush generate plugin:field:type — Generate a custom Field Type plugin.
drush generate plugin:field:typedrush generate theme — Scaffold a new custom theme with all required files.
drush generate themedrush generate hook — Generate an implementation of a Drupal hook in a module's .module file.
drush generate hookCommon Deployment Workflow
git pull && drush deploy — Pull latest code and run the full Drupal deploy sequence (updb + cim + cr + deploy:hook).
git pull && drush deploydrush state:set system.maintenance_mode 1 --input-format=integer && drush cr — Step 1: Enable maintenance mode before deployment.
drush state:set system.maintenance_mode 1 --input-format=integer && drush crdrush updatedb -y && drush config:import -y && drush cache:rebuild — Step 2: Run DB updates, import config, rebuild caches.
drush updatedb -y && drush config:import -y && drush cache:rebuilddrush state:set system.maintenance_mode 0 --input-format=integer && drush cr — Step 3: Disable maintenance mode after deployment.
drush state:set system.maintenance_mode 0 --input-format=integer && drush crdrush sql:dump --gzip --result-file=pre-deploy.sql && drush deploy — Create a DB backup before running the deploy command.
drush sql:dump --gzip --result-file=pre-deploy.sql && drush deploydrush sql:sync @prod @self && drush config:import -y && drush cr — Pull production DB locally, import local config, rebuild cache.
drush sql:sync @prod @self && drush config:import -y && drush cr Conclusion
Drush turns recurring Drupal chores into short, repeatable commands – exactly what you need for clean deployments and reproducible environments. A few commands deserve respect, though: sql:drop drops every single table in your database, sql:cli and sql:dump expose your database credentials, and updatedb (updb) as well as cache:rebuild (cr) should only be run deliberately in production, ideally under maintenance mode. Take a database dump before any major change, and an accidental misstep is quickly undone.
Further Reading
- Drush documentation – official documentation with command reference and guides
- Drupal documentation – official Drupal docs covering development and operations