# 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.

Source: https://www.jpkc.com/db/en/cheatsheets/build-languages/drush/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Core & Info

`drush --version` — Show the installed Drush version.

```bash
drush --version
```

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

```bash
drush status
```

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

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

`drush list` — List all available Drush commands.

```bash
drush list
```

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

```bash
drush list --filter=config
```

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

```bash
drush help config:export
```

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

```bash
drush core:requirements
```

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

```bash
drush core:edit
```

## Cache

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

```bash
drush cache:rebuild
```

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

```bash
drush cr
```

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

```bash
drush cache:clear render
```

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

```bash
drush cache:get my_module.data default
```

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

```bash
drush cache:set my_key "hello" default
```

## Configuration

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

```bash
drush config:export
```

`drush cex` — Alias for config:export.

```bash
drush cex
```

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

```bash
drush config:import
```

`drush cim` — Alias for config:import.

```bash
drush cim
```

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

```bash
drush config:import --partial
```

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

```bash
drush config:status
```

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

```bash
drush config:diff system.site
```

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

```bash
drush config:get system.site
```

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

```bash
drush config:get system.site name
```

`drush config:set <name> <key> <value>` — Set a specific configuration key to a new value.

```bash
drush config:set system.site name "My Drupal Site"
```

`drush config:delete <name>` — Delete a configuration object entirely from the active store.

```bash
drush config:delete my_module.settings
```

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

```bash
drush config:edit system.performance
```

## Modules & Themes (pm)

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

```bash
drush pm:list
```

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

```bash
drush pm:list --status=enabled
```

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

```bash
drush pm:list --type=module
```

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

```bash
drush pm:enable views devel
```

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

```bash
drush en admin_toolbar
```

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

```bash
drush pm:uninstall devel
```

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

```bash
drush pm:info views
```

## Updates & Deploy

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

```bash
drush updatedb
```

`drush updb` — Alias for updatedb.

```bash
drush updb
```

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

```bash
drush updatedb --no-post-updates
```

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

```bash
drush deploy
```

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

```bash
drush deploy:hook
```

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

```bash
drush core:update
```

`drush state:set system.maintenance_mode 1 --input-format=integer && drush cr` — Enable maintenance mode and clear cache (before a deployment).

```bash
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).

```bash
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

```bash
drush sql:cli
```

`drush sql:query "<query>"` — Execute a SQL query directly against the Drupal database. Alias: sqlq

```bash
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.

```bash
drush sql:dump > backup.sql
```

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

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

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

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

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

```bash
drush sql:drop
```

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

```bash
drush sql:sanitize
```

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

```bash
drush sql:sanitize --sanitize-password=admin
```

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

```bash
drush sql:connect
```

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

```bash
drush sql:create
```

## User Management

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

```bash
drush user:login
```

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

```bash
drush uli
```

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

```bash
drush user:login --name=editor
```

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

```bash
drush user:info admin
```

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

```bash
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

```bash
drush user:password admin newpassword123
```

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

```bash
drush upwd admin admin
```

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

```bash
drush user:block spammer
```

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

```bash
drush user:unblock john
```

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

```bash
drush user:cancel olduser
```

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

```bash
drush user:role:add editor john
```

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

```bash
drush user:role:remove editor john
```

## State & Variables

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

```bash
drush state:get system.cron_last
```

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

```bash
drush state:set system.maintenance_mode 1
```

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

```bash
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().

```bash
drush cron
```

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

```bash
drush queue:list
```

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

```bash
drush queue:run mymodule_import_queue
```

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

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

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

```bash
drush queue:delete mymodule_import_queue
```

## Watchdog (Logging)

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

```bash
drush watchdog:show
```

`drush ws` — Alias for watchdog:show.

```bash
drush ws
```

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

```bash
drush watchdog:show --count=50
```

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

```bash
drush watchdog:show --severity=error
```

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

```bash
drush watchdog:show --type=php
```

`drush watchdog:show --filter=<string>` — Filter watchdog messages containing a specific string.

```bash
drush watchdog:show --filter="Access denied"
```

`drush watchdog:tail` — Follow the watchdog log in real-time (like tail -f). Alias: wt

```bash
drush watchdog:tail
```

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

```bash
drush watchdog:delete --severity=debug
```

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

```bash
drush watchdog:delete --all
```

## Site Install

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

```bash
drush site:install
```

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

```bash
drush si minimal
```

`drush site:install --db-url=mysql://user:pass@localhost/dbname` — Install Drupal with a specific database connection string.

```bash
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.

```bash
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.

```bash
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.

```bash
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.

```bash
drush @prod cache:rebuild
```

`drush site:alias` — Show all defined site aliases.

```bash
drush site:alias
```

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

```bash
drush sql:sync @prod @self
```

`drush rsync @<source>:%files/ @<target>:%files/` — Sync files between two site aliases using rsync.

```bash
drush rsync @prod:%files/ @self:%files/
```

`drush --uri=<uri> <command>` — Run a command targeting a specific multisite URI.

```bash
drush --uri=sub.example.com cache:rebuild
```

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

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

## Generate (Code Generation)

`drush generate` — List all available code generators.

```bash
drush generate
```

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

```bash
drush generate module
```

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

```bash
drush generate controller
```

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

```bash
drush generate service
```

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

```bash
drush generate form
```

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

```bash
drush generate plugin:block
```

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

```bash
drush generate plugin:field:type
```

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

```bash
drush generate theme
```

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

```bash
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).

```bash
git pull && drush deploy
```

`drush state:set system.maintenance_mode 1 --input-format=integer && drush cr` — Step 1: Enable maintenance mode before deployment.

```bash
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.

```bash
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.

```bash
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.

```bash
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.

```bash
drush sql:sync @prod @self && drush config:import -y && drush cr
```

<!-- PROSE:outro -->
## 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](https://www.drush.org/) – official documentation with command reference and guides
- [Drupal documentation](https://www.drupal.org/docs) – official Drupal docs covering development and operations
<!-- PROSE:outro:end -->

## Related Commands

- [artisan](https://www.jpkc.com/db/en/cheatsheets/build-languages/artisan/) – command-line tool for the Laravel framework
- [cargo](https://www.jpkc.com/db/en/cheatsheets/build-languages/cargo/) – build tool and package manager for Rust
- [composer](https://www.jpkc.com/db/en/cheatsheets/build-languages/composer/) – dependency manager for PHP projects

