Most used Drush commands for Drupal 8, 9, 10

It is essential for every Drupal developer to know how to use Drush tool to manage Drupal installation, as it is a very valuable skill that save a lot of time on routine operations or configuration tasks. I'll list the Drush commands I use every day in my Drupal development process.

Why Drush is awesome? Just one line  - the task is done, try it!

Example of Drush command execution
Example of Drush command execution

As a requirement to start using Drush, you must first ensure that you have Drush installed in your Drupal development environment or Drush is available globally at your system.

Included in this reference are all the Drush commands for Drush versions 8,9. Don't forget to learn more about Drush in official documentation.
 

 

cache:clear (cc) and cache:rebuild (cr, rebuild) - Control Drupal cache system.

Module: core

Examples:

drush cache:clear
drush cc
drush cc bin entity,render,page

Simple command to clear the cache (when adding a features to the site or changes in configuration). You can clear all caches or specific one.

Examples:

drush cache:rebuild
drush cr

Command to rebuild a Drupal site. In addition Drush cache and Drupal's render cache will be cleared.

 

state:set (sset) and state:get (sget) - Control Drupal state storage.

Module: core

Examples:

drush state:set system.maintenance_mode TRUE

Sometimes needed to quickly set site to maintenance mode, state:set command can help, any other state settings can be changed.

Examples:

drush state:get system.cron_last

Easy way to get last cron execution time.

 

pm:enable (en) and pm:uninstall (pmu) - Enable and Uninstall modules.

Module:code

Examples:

drush pm:enable token
drush pm:enable token,metatag
drush en token,metatag

Command to enable module or modules that are available for your Drupal site. Module need to be downloaded before using this command.

 

Examples:

drush pm:uninstall token
drush pm:uninstall token,metatag
drush pmu token,metatag

Command to uninstall selected module or modules.

 

updatedb (updb) and updatedb:status (updbst) - Apply pending database updates required by code or modules, check updates status.

Module: code

Examples:

drush updatedb

Run any pending database updates. Usually required if you update Drupal code files or modules.

Examples:

drush updatedb:status

Check if any database updates are pending.

 

watchdog:show (wd-show, ws) and watchdog:list (wd-list) - Display Drupal Watchdog log messages.

Module:code

Examples:

drush watchdog:show

Alternative of going to the watchdog page to see errors and warnings, you can check logs in a command line.

Examples:

drush watchdog:list

Output watchdog messages by cotegory.

 

core:cron - Run all cron tasks.

Module: code

Examples:

drush core:cron
drush cron

Run cron hooks in all active modules for current site.

 

core:topic (topic) - Show documentation for a specific topic.

Module: code

Examples:

drush core:topic docs:readme
drush topic docs:cron

Very useful command to get help on various topics about Drush & Drupal.

 

sql:dump - Exports the Drupal Database.

Module: code

Examples:

drush sql:dump --result-file=drupal8.sql
drush sql:dump --gzip --skip-tables-key=common --result-file=drupal8.sql
drush sql:dump > database.sql

Simple command to export Drupal SQL Database to a file.

 

sql:query (sqlq) and sql:cli (sqlc) - Execute a query on a database and open a SQL command-line command interface.

Module: code

Examples:

drush sql:query "SELECT * FROM node WHERE nid=1"
drush sql:query "SELECT * FROM users"

Run any SQL query, used MYSQL statement to select Node table record with specific NID.

 

Examples:

drush sql:cli
drush sql:cli < drupal8.sql

Access SQL command line, run SQL statements from selected files.

 

user:password - Set the password for the user account.

Module: code

Examples:

drush user:password newuser "newpassword"

User Password change tool.

 

user:login (uli) - Output a one time login link to login to the site.

Module: code

Examples:

drush user:login
drush user:login --name=admin
drush user:login --mail=admin@drupal.com

Handy command to quickly login to the site as a specific used.

 

config:export and config:import - Export & Import Drupal Site Configuration.

Module: code

Examples:

drush config:export
drush config:export --destination=config/site

Export Drupal configuration to a directory.

 

Examples:

drush config:import
drush config:import --destination=config/site

Import Drupal configuration from a directory.

 

pm:security (sec) and pm:security-php (sec-php) - Check for pending security updates in Drupal and PHP extensions.

Module: code

Examples:

drush pm:security

Check Drupal packages for any security updates.

 

Examples:

drush pm:security-php

Check non-Drupal PHP packages security updates.

 

 

Conclusion

As we can see, Drush is very helpful in day to day developing to manage simple tasks.

Don't forgot to check Drush official documentation, or checking --help attribute on Drush commands for additional help