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 --version

drush status — Show the Drupal site status: root, URI, database, PHP version, Drush version, etc.

drush status

drush status --fields=drupal-version,db-status — Show only specific status fields.

drush status --fields=drupal-version,db-status

drush list — List all available Drush commands.

drush list

drush list --filter=<group> — List commands in a specific group (e.g. cache, config, pm, sql, user).

drush list --filter=config

drush help <command> — Show help and all options for a specific Drush command.

drush help config:export

drush core:requirements — Show Drupal's status report (same as admin/reports/status). Lists any site issues.

drush core:requirements

drush core:edit — Open the active services.yml file in your default editor.

drush core:edit

Cache

drush cache:rebuild — Rebuild all caches. The Drupal 8+ equivalent of cache-clear all. Alias: cr

drush cache:rebuild

drush cr — Alias for cache:rebuild. The most commonly used Drush command.

drush cr

drush cache:clear <bin> — Clear a specific cache bin (e.g. render, page, menu, css_js, theme, token).

drush cache:clear render

drush cache:get <cid> <bin> — Fetch and display a specific cache item by its cache ID.

drush cache:get my_module.data default

drush cache:set <cid> <data> <bin> — Cache an arbitrary value into a specific bin.

drush cache:set my_key "hello" default

Configuration

drush config:export — Export the active Drupal configuration to the sync directory (config/sync). Alias: cex

drush config:export

drush cex — Alias for config:export.

drush cex

drush config:import — Import configuration from the sync directory into the active database config. Alias: cim

drush config:import

drush cim — Alias for config:import.

drush cim

drush config:import --partial — Import only the config files present in the sync directory, ignoring missing ones.

drush config:import --partial

drush config:status — Show which configuration items differ between active (DB) and sync (files) directories.

drush config:status

drush config:diff <name> — Show the diff between active and synced config for a specific config item.

drush config:diff system.site

drush config:get <name> — Display the full value of a configuration object.

drush config:get system.site

drush config:get <name> <key> — Get a specific key from a configuration object.

drush config:get system.site name

drush 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.settings

drush config:edit <name> — Open a configuration item in your editor. Changes are saved on exit.

drush config:edit system.performance

Modules & Themes (pm)

drush pm:list — List all installed modules and themes with their status. Alias: pml

drush pm:list

drush pm:list --status=enabled — List only enabled modules and themes.

drush pm:list --status=enabled

drush pm:list --type=module — List only modules (not themes or profiles).

drush pm:list --type=module

drush pm:enable <module> — Enable one or more modules. Drush handles dependencies automatically. Alias: en

drush pm:enable views devel

drush en <module> — Alias for pm:enable.

drush en admin_toolbar

drush pm:uninstall <module> — Uninstall one or more modules and remove their configuration/data. Alias: pmu

drush pm:uninstall devel

drush pm:info <module> — Show detailed information about a module or theme.

drush pm:info views

Updates & Deploy

drush updatedb — Run any pending database update hooks (from hook_update_N). Alias: updb

drush updatedb

drush updb — Alias for updatedb.

drush updb

drush updatedb --no-post-updates — Run DB updates but skip post-update hooks.

drush updatedb --no-post-updates

drush deploy — Standard deployment sequence: updatedb, config:import, cache:rebuild, deploy:hook. Use after pulling code.

drush deploy

drush deploy:hook — Run all pending hook_deploy_NAME() functions (post-deploy tasks).

drush deploy:hook

drush core:update — Apply any pending Drupal core updates (includes updb, cim, cr).

drush core:update

drush 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 cr

drush 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 cr

Database

drush sql:cli — Open an interactive SQL shell connected to the Drupal database. Alias: sqlc

drush sql:cli

drush 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.sql

drush sql:dump --gzip --result-file=<file> — Export the database to a compressed SQL file.

drush sql:dump --gzip --result-file=backup.sql

drush sql:dump --tables-list=<tables> — Dump only specific tables (comma-separated).

drush sql:dump --tables-list=node,node_field_data

drush sql:drop — Drop all tables in the Drupal database. Use with caution!

drush sql:drop

drush sql:sanitize — Sanitize the database by obfuscating emails and resetting passwords. Use on production dumps before sharing.

drush sql:sanitize

drush sql:sanitize --sanitize-password=<pass> — Sanitize and set a specific password for all users.

drush sql:sanitize --sanitize-password=admin

drush sql:connect — Print the DB connection string for use with other tools.

drush sql:connect

drush sql:create — Create the database defined in settings.php (if it doesn't exist).

drush sql:create

User Management

drush user:login — Generate a one-time login URL for user 1 (admin). Alias: uli

drush user:login

drush uli — Alias for user:login. Opens a one-time admin login URL.

drush uli

drush user:login --name=<username> — Generate a one-time login URL for a specific user.

drush user:login --name=editor

drush user:info <username> — Show information about a specific user account.

drush user:info admin

drush user:create <username> --mail=<email> --password=<pass> — Create a new user account.

drush user:create john --mail=john@example.com --password=secret

drush user:password <username> <password> — Set a new password for a user account. Alias: upwd

drush user:password admin newpassword123

drush upwd <username> <password> — Alias for user:password.

drush upwd admin admin

drush user:block <username> — Block (disable) a user account.

drush user:block spammer

drush user:unblock <username> — Unblock a previously blocked user account.

drush user:unblock john

drush user:cancel <username> — Cancel (delete) a user account.

drush user:cancel olduser

drush user:role:add <role> <username> — Add a role to an existing user.

drush user:role:add editor john

drush user:role:remove <role> <username> — Remove a role from a user.

drush user:role:remove editor john

State & Variables

drush state:get <key> — Get the value of a Drupal state variable.

drush state:get system.cron_last

drush state:set <key> <value> — Set a Drupal state variable to a new value.

drush state:set system.maintenance_mode 1

drush state:delete <key> — Delete a Drupal state variable.

drush state:delete mymodule.custom_flag

Cron & Queue

drush cron — Run all cron tasks that are due, as defined by each module's hook_cron().

drush cron

drush queue:list — List all available queues with their item counts.

drush queue:list

drush queue:run <queue> — Process all items in a specific queue.

drush queue:run mymodule_import_queue

drush queue:run <queue> --items-limit=<n> — Process only a limited number of queue items.

drush queue:run mymodule_import_queue --items-limit=50

drush queue:delete <queue> — Delete all items from a specific queue without processing them.

drush queue:delete mymodule_import_queue

Watchdog (Logging)

drush watchdog:show — Show recent watchdog log entries. Alias: ws

drush watchdog:show

drush ws — Alias for watchdog:show.

drush ws

drush watchdog:show --count=<n> — Show the last N watchdog entries (default: 10).

drush watchdog:show --count=50

drush watchdog:show --severity=<level> — Filter by severity: debug, info, notice, warning, error, critical, alert, emergency.

drush watchdog:show --severity=error

drush watchdog:show --type=<type> — Filter watchdog messages by type (e.g. php, cron, user, system).

drush watchdog:show --type=php

drush 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:tail

drush watchdog:delete --severity=<level> — Delete watchdog entries of a specific severity level.

drush watchdog:delete --severity=debug

drush watchdog:delete --all — Delete all watchdog entries.

drush watchdog:delete --all

Site Install

drush site:install — Install Drupal using the standard profile. Drops and recreates all tables. Alias: si

drush site:install

drush si <profile> — Install Drupal using a specific installation profile.

drush si minimal

drush 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/drupal

drush 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.com

drush 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.com

drush site:install --existing-config — Install Drupal from existing configuration in the config/sync directory.

drush site:install --existing-config

Aliases & Multi-site

drush @<alias> <command> — Execute a command on a remote or alternate Drupal site defined by a site alias.

drush @prod cache:rebuild

drush site:alias — Show all defined site aliases.

drush site:alias

drush sql:sync @<source> @<target> — Copy the database from one site alias to another (e.g. prod to local).

drush sql:sync @prod @self

drush 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:rebuild

drush --root=/var/www/drupal <command> — Target a Drupal installation at a specific directory path.

drush --root=/var/www/drupal status

Generate (Code Generation)

drush generate — List all available code generators.

drush generate

drush generate module — Interactively scaffold a new custom module with all boilerplate files.

drush generate module

drush generate controller — Generate a Drupal controller class for a module.

drush generate controller

drush generate service — Generate a Drupal service class and service definition.

drush generate service

drush generate form — Generate a Drupal form class (ConfigFormBase or FormBase).

drush generate form

drush generate plugin:block — Generate a custom Block plugin class.

drush generate plugin:block

drush generate plugin:field:type — Generate a custom Field Type plugin.

drush generate plugin:field:type

drush generate theme — Scaffold a new custom theme with all required files.

drush generate theme

drush generate hook — Generate an implementation of a Drupal hook in a module's .module file.

drush generate hook

Common Deployment Workflow

git pull && drush deploy — Pull latest code and run the full Drupal deploy sequence (updb + cim + cr + deploy:hook).

git pull && drush deploy

drush 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 cr

drush 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:rebuild

drush 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 cr

drush 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 deploy

drush 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

  • artisan – command-line tool for the Laravel framework
  • cargo – build tool and package manager for Rust
  • composer – dependency manager for PHP projects