How to use the command 'drush' (with examples)

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 management
  • en: the command to enable a module
  • foo: 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 management
  • pmu: the short form of “pm-uninstall”, the command to uninstall a module
  • foo: 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 management
  • cr: 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 management
  • cc: the short form of “cache-clear”, the command to clear specific caches
  • css-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.

Related Posts

How to use the command pkginfo (with examples)

How to use the command pkginfo (with examples)

The command pkginfo is used to query the package database on a CRUX system.

Read More
hadolint (with examples)

hadolint (with examples)

Docker is a popular containerization platform used to package applications and their dependencies into a standardized unit known as a container.

Read More
How to use the command xo (with examples)

How to use the command xo (with examples)

The xo command is a pluggable, zero-configuration linting utility for JavaScript.

Read More