How to use the command 'drush' (with examples)
Drush is a command-line shell and scripting interface for Drupal. It provides a convenient way to manage and administer a Drupal website through the command line.
Use case 1: Enable a module
Code:
drush en foo
Motivation: Enabling a module is necessary when you want to add new functionality to your Drupal website. In some cases, enabling a certain module may be a prerequisite for other modules to work.
Explanation:
drush
: the command-line tool for Drupal managementen
: the command to enable a modulefoo
: the name of the module to enable
Example output:
Module foo enabled successfully.
foo.install module enabled.
foo.module module enabled.
Use case 2: Uninstall a module
Code:
drush pmu foo
Motivation: Uninstalling a module is useful when you no longer need its functionality or when troubleshooting an issue caused by a specific module.
Explanation:
drush
: the command-line tool for Drupal managementpmu
: the short form of “pm-uninstall”, the command to uninstall a modulefoo
: the name of the module to uninstall
Example output:
The following extensions will be uninstalled:
foo
Do you really want to continue? (y/n): y
Log messages:
Uninstalling foo.
Foo was successfully uninstalled.
Use case 3: Clear all caches
Code:
drush cr
Motivation: Clearing the cache is often necessary to reflect changes made to the website, such as updating Drupal configuration or applying updates to modules and themes.
Explanation:
drush
: the command-line tool for Drupal managementcr
: the short form of “cache-rebuild”, the command to clear all caches
Example output:
Cache rebuild complete. [ok]
Use case 4: Clear CSS and JavaScript caches
Code:
drush cc css-js
Motivation: Clearing the CSS and JavaScript caches is useful when you have made changes to the stylesheets or JavaScript files used in your Drupal theme.
Explanation:
drush
: the command-line tool for Drupal managementcc
: the short form of “cache-clear”, the command to clear specific cachescss-js
: the cache group containing CSS and JavaScript caches
Example output:
CSS and JS cache cleared. [success]
Conclusion:
Drush is a powerful command-line tool that allows for efficient management of Drupal websites. It provides a convenient way to enable and uninstall modules, clear caches, and perform various other administrative tasks. By using Drush, Drupal administrators can save time and effort by performing these tasks quickly through the command line.