drush

Use when working with Drush CLI for Drupal site management - running cache rebuilds, config imports/exports, database queries, PHP evaluation, module management, user operations, or troubleshooting Drush commands that no longer exist

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "drush" with this command: npx skills add factorial-io/skills/factorial-io-skills-drush

Drush CLI Reference

Command-line interface for Drupal site management. Drush runs in the Drupal bootstrap context, giving full access to the Drupal API.

Command Structure

All commands follow: drush <command> [arguments] [--options]

Most commands have short aliases. Use drush list to see all available commands, drush <command> --help for details.

In DDEV: Prefix with ddev (e.g., ddev drush cr).

Quick Reference

TaskCommandAlias
Cache rebuilddrush cache:rebuilddrush cr
Config exportdrush config:exportdrush cex
Config importdrush config:importdrush cim
Config getdrush config:get <name>drush cget <name>
Config setdrush config:set <name> <key> <value>drush cset <name> <key> <value>
Database updatedrush updatedbdrush updb
Module installdrush pm:install <module>drush en <module>
Module uninstalldrush pm:uninstall <module>drush pmu <module>
List modulesdrush pm:listdrush pml
User login linkdrush user:logindrush uli
User infodrush user:information <name>
Watchdog logsdrush watchdog:showdrush ws (requires dblog module)
Status overviewdrush statusdrush st
Run crondrush cron
State getdrush state:get <key>drush sget <key>
State setdrush state:set <key> <value>drush sset <key> <value>
Deploy (updb+cim+cr)drush deploy
Code generationdrush generatedrush gen
Site requirementsdrush core:requirementsdrush rq
Watchdog taildrush watchdog:taildrush wt (requires dblog module)
Queue listdrush queue:list
Queue rundrush queue:run <name>

Running PHP Code

Drush can evaluate arbitrary PHP within full Drupal bootstrap context.

Inline PHP with eval

# Simple expression
drush php:eval "echo \Drupal::VERSION;"

# Load and inspect an entity
drush php:eval "\$node = \Drupal\node\Entity\Node::load(1); echo \$node->getTitle();"

# Query entities
drush php:eval "\$ids = \Drupal::entityTypeManager()->getStorage('node')->getQuery()->accessCheck(FALSE)->condition('type', 'article')->range(0, 5)->execute(); print_r(\$ids);"

# Access a service
drush php:eval "echo \Drupal::service('extension.list.module')->getPath('node');"

# Get current user
drush php:eval "echo \Drupal::currentUser()->getAccountName();"

Shell escaping: Use single quotes around the PHP string in fish/zsh to avoid $ expansion, or escape \$ in double quotes.

Interactive PHP shell

# Opens interactive REPL with Drupal bootstrapped
drush php:cli

Useful for exploring APIs interactively. Tab completion available for classes/functions.

Running PHP scripts

# Execute a PHP file with full Drupal bootstrap
drush php:script path/to/script.php

# Pass arguments (available as $extra in the script)
drush php:script path/to/script.php -- arg1 arg2

Executing SQL Commands

Direct SQL queries

# Run a SQL query directly
drush sql:query "SELECT nid, title FROM node_field_data LIMIT 10"

# Count content by type
drush sql:query "SELECT type, COUNT(*) as count FROM node_field_data GROUP BY type"

# Check a specific table (MySQL-specific syntax)
drush sql:query "DESCRIBE users_field_data"

# Show tables matching a pattern (MySQL-specific)
drush sql:query "SHOW TABLES LIKE '%node%'"

Note: DESCRIBE and SHOW TABLES are MySQL-specific. For PostgreSQL use \d table_name in sql:cli.

Database shell and dumps

# Open interactive database client (mysql/psql)
drush sql:cli

# Create database dump
drush sql:dump > dump.sql
drush sql:dump --result-file=/tmp/dump.sql
drush sql:dump --gzip --result-file=/tmp/dump.sql  # produces dump.sql.gz

# Import SQL file
drush sql:cli < dump.sql

# Show database connection info
drush sql:conf

# Sanitize user data (emails, passwords) for safe copies
drush sql:sanitize

# Drop all tables (use with caution)
drush sql:drop

Retrieving Configuration

Get configuration values

# Get entire config object (YAML output)
drush config:get system.site
drush cget system.site

# Get a specific key
drush config:get system.site name
drush cget system.site page.front

# List all config names (no config:list command in Drush 13+)
drush php:eval 'foreach (\Drupal::service("config.storage")->listAll("system") as $name) echo "$name\n";'

# Get active vs sync diff
drush config:status

Edit and set configuration

# Set a single value
drush config:set system.site name "My Site"
drush cset system.site name "My Site"

# Set nested value
drush config:set system.site page.front "/node"

# Edit full config object in editor
drush config:edit system.site

# Delete a config object
drush config:delete <config-name>

Config export/import workflow

# Export active config to sync directory
drush cex

# Show pending changes (what would be imported)
drush config:status

# Import config from sync directory
drush cim

# Import partial (only imports items in sync dir, does not delete active-only config)
drush cim --partial

# Import from a non-default directory
drush cim --source=/path/to/config

# Export single config item to stdout
drush config:get system.site --format=yaml

Module Management

# List all modules with status
drush pml
drush pml --status=enabled
drush pml --type=module --status="not installed"

# Install module(s)
drush en module_name
drush en module_one module_two

# Uninstall module(s)
drush pmu module_name

# Check if module is enabled
drush pml --filter=module_name

User Management

# Generate one-time login link
drush uli
drush uli --uid=1
drush uli admin

# Create user
drush user:create username --mail="user@example.com" --password="pass"

# Add role to user
drush user:role:add editor admin

# Remove role
drush user:role:remove editor admin

# Block/unblock user
drush user:block username
drush user:unblock username

# Reset password
drush user:password admin "newpassword"

Roles and Permissions

Inspecting roles

# List all roles with their permissions
drush role:list
drush role:list --format=table
drush role:list --format=json

# Get permissions for a specific role via config
drush cget user.role.editor

# Check a user's roles
drush user:information admin --format=json

Checking permissions

# List all available permissions (grep to search)
drush php:eval 'echo implode("\n", array_keys(\Drupal::service("user.permissions")->getPermissions()));'

# Search for specific permissions
drush php:eval 'echo implode("\n", array_keys(\Drupal::service("user.permissions")->getPermissions()));' | grep administer

Managing permissions

# Grant permission to a role
drush role:perm:add anonymous 'access content'

# Grant multiple permissions
drush role:perm:add editor 'access content,administer nodes'

# Remove permission from a role
drush role:perm:remove anonymous 'access content'

# Create / delete a role
drush role:create editor Editor
drush role:delete editor

Code Generation

Drush includes scaffolding for modules, plugins, forms, entities, and more via drush generate (powered by drupal-code-generator).

# Interactive: pick a generator from the list
drush generate

# Generate a specific component
drush generate module
drush generate controller
drush generate form:config
drush generate plugin:block
drush generate entity:content
drush generate hook

# Preview what would be generated (no files written)
drush generate controller --dry-run

# Pre-fill answers to skip interactive prompts
drush generate controller --answer=Example --answer=example

# See all available generators
drush generate --dry-run

Common generators: module, controller, field, hook, form:simple, form:config, form:confirm, plugin:block, plugin:action, entity:content, entity:configuration, service-provider, drush:command.

Run drush generate <name> --help for details on a specific generator.

Useful Options

OptionDescription
--format=jsonJSON output (useful for scripting/parsing)
--format=yamlYAML output
--format=tableTable output (default for many commands)
-yAuto-confirm prompts
-vVerbose output
--debugDebug output
--uri=http://example.comSet base URI for commands
--root=/path/to/drupalSet Drupal root

Deprecated and Removed Commands

Commands that NO LONGER EXIST in modern Drush (12+). Do NOT suggest these:

Removed CommandWhat to Use Instead
drush entity-updates / drush entupRemoved entirely. Entity schema updates are handled by drush updatedb (drush updb). If hook_update_N does not cover your change, write a custom update hook.
drush pm-download / drush dlUse composer require drupal/<module>
drush pm-update / drush upUse composer update then drush updb
drush pm-enable (old syntax)Use drush pm:install / drush en
drush pm-disable / drush disUse drush pm:uninstall / drush pmu (no "disable" concept in modern Drupal)
drush features-*Features module commands; use config management instead
drush sql-syncStill exists as sql:sync but requires site aliases. Without aliases, use drush sql:dump + transfer, or tools like phabalicious copy-from
drush core-rsyncStill exists as core:rsync but requires site aliases. Without aliases, use rsync directly or deployment tools
drush registry-rebuild / drush rrRemoved. Use drush cr instead
drush variable-get/setVariables replaced by State API (drush sget/drush sset) or Config API (drush cget/drush cset)

General rule: If a command uses a hyphen (e.g., entity-updates), it is likely old Drush syntax. Modern Drush uses colons (e.g., cache:rebuild).

Common Mistakes

WrongRightWhy
drush entity-updatesdrush updbentity-updates removed in Drush 11+
drush dl modulecomposer require drupal/modulePackage management via Composer now
drush upcomposer update && drush updbUpdates via Composer, then run DB updates
drush dis moduledrush pmu moduleNo disable concept; uninstall instead
drush cim without drush cr after issuesdrush cr && drush cimCache rebuild can resolve import errors
drush variable-get xdrush sget x or drush cget xVariables removed; use State or Config API
Running drush cim before drush updbdrush updb && drush cim or drush deployUpdate hooks may add schemas needed by config import
Manual drush updb && drush cim && drush crdrush deploydeploy handles correct order and error handling
drush cim/drush updb in scripts without -yAdd -y flagThese commands prompt for confirmation and hang without it
Forgetting accessCheck(FALSE) in entity queries via php:evalAlways add ->accessCheck(FALSE)Required since Drupal 9.2, throws deprecation without it

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

himalaya

No summary provided by upstream source.

Repository SourceNeeds Review
General

phabalicious

No summary provided by upstream source.

Repository SourceNeeds Review
General

jujutsu

No summary provided by upstream source.

Repository SourceNeeds Review
Security

security-audit

No summary provided by upstream source.

Repository SourceNeeds Review