[Drush] Frequently used drush commands

By | 29th Jul 2015 | 2 min read


As part of Drupal development project, we always use drush commands. Drush or Drupal shell refers to a command-line shell and scripting interface for Drupal. Drush enables developers to effectively manage and maintain their Drupal websites from the server command line. A few frequently used commands are listed below.

Download a module.

 drush dl module-name 

It will download the latest recommended module release from drupal site.

 drush dl --select module-name 

It will show all available versions. Then we can select the option that we want.

 

 

Enable a module.

 drush en module-name 

It will ask to download the module, if it's not found.

Disable a module.

 drush dis module-name 

Uninstall and Reinstall a module

 drush dre module-name 

 

 

Update a module.

 drush up module-name 

Run update.php

 drush updb 

Run tests.

 drush test-run 

This will run tests, if you use automated testing. Note that you must use the --uri option. URI of the drupal site to be used (only needed in multisite environments or when running on an alternate port).

Clear the cache.

 drush cc all 

To clear all cached data from site

 drush cc css-js 

To clear all css and js cache from site

Clear all the cache data, even if Drupal is broken.

 drush sql-query "DELETE FROM cache" 

sql-query command executes sql queries in the database where Drupal is installed.

Set a password for a user.

 drush upwd --password="asdf" admin 

To revert a custom feature, update the database to match the code.

 drush fr feature_name 

Run cron.

 drush cron 

Flush image styles.

 drush image-flush all 

Set a variable.

 drush vset variable_name 'value'. 

Get the value of a variable.

 drush vget variable_name 

Open a MySQL console logged in.

 drush sql-cli 

Export a backup of the database.

 drush sql-dump | gzip --stdout > filename.sql.gz 

Remove all database tables (empty the database).

 drush sql-drop 

This command is useful before importing a database backup of the site.

If you want to see all the main information and status of the site.

 drush status 

Create a user account.

 drush user-create <user-name> --mail="[email protected]" 

If you regularly use drush commands in drupal applications development, this will definitely help you a lot.