Some basic drush commands

Submitted by phannphong on 21 February, 2019
basic drush commands

Drush is a supporting tool, which is important for any Drupal developers. It helps executing a task with many steps simpler through one command. It's also really helpful in deployment process through integrating it in script.

I will share some basic Drush commands that I usually use:

1. Clear cache / Cache rebuild.

For Drupal 7

drush cc all

For Drupal 8/9

drush cr

2. Delete all tables in the database (available on Drupal 7/8/9).

drush sql-drop

3. Set password for the account which you know the username(available on Drupal 7/8/9).

drush upwd <username> --password="<password_you_want>"

Example:

drush upwd admin --password="admin"

By executing the above command line, the password of admin (account with "admin" is username) is admin.

This is a useful command line when you don't know or forget the password of the account.

4. View list the core and the contributed modules have a new version (available only Drupal 7).

drush ups

5. Update core and contributed module with the latest version (available only Drupal 7).

drush up

This command line will update both core and contributed modules at the same time.

If you just want to update for core or individual contributed modules, you'll use:

drush up drupal

(for core)

drush up <module_machine_name_1>, <module_machine_name_2>, <module_machine_name_3>

(Note: module_machine_name_n is the last path of the url link to the contributed module)

You should backup source code and database before running this command line.

6. Revert schema version of core or contributed modules.

For Drupa7

drush ev "drupal_set_installed_schema_version('<module_machine_name>', <number_version>)"

Example:

drush ev "drupal_set_installed_schema_version('entityreference', 7002)"

For Drupal 8, 9, 10, 11

drush eval '\Drupal::service("update.update_hook_registry")->setInstalledVersion("MODULE", "930N")';

7. Get value of configuration in the site.

For Drupal 7

drush variable-get <key_configuration>

Example:

drush variable-get site_slogan
drush vget raven_release

For Drupal 8+

drush config-get <key_configuration>

Example:

drush config-get system.site

8. Set value of configuration in the site.

For Drupal 7

drush variable-set <key_configuration>

Example:

drush variable-set site_slogan 'Sharing drupal tutorials'
drush vset raven_release v2.0.1

For Drupal 8+

drush config-set <key_configuration> <child_key_configuration>

Example:

drush config-set system.site slogan 'Sharing drupal tutorials'
drush cset raven.settings release v2.0.1

You can find more Drush commands at https://drushcommands.com/

Reference: https://drushcommands.com

Comments

basic drush commands

Drush is a supporting tool, which is important for any Drupal developers. It helps executing a task with many steps simpler through one command. It's also really helpful in deployment process through integrating it in script.

I will share some basic Drush commands that I usually use:

1. Clear cache / Cache rebuild.

For Drupal 7

drush cc all

For Drupal 8/9

drush cr

2. Delete all tables in the database (available on Drupal 7/8/9).

drush sql-drop

3. Set password for the account which you know the username(available on Drupal 7/8/9).

drush upwd <username> --password="<password_you_want>"

Example:

drush upwd admin --password="admin"

By executing the above command line, the password of admin (account with "admin" is username) is admin.

This is a useful command line when you don't know or forget the password of the account.

4. View list the core and the contributed modules have a new version (available only Drupal 7).

drush ups

5. Update core and contributed module with the latest version (available only Drupal 7).

drush up

This command line will update both core and contributed modules at the same time.

If you just want to update for core or individual contributed modules, you'll use:

drush up drupal

(for core)

drush up <module_machine_name_1>, <module_machine_name_2>, <module_machine_name_3>

(Note: module_machine_name_n is the last path of the url link to the contributed module)

You should backup source code and database before running this command line.

6. Revert schema version of core or contributed modules.

For Drupa7

drush ev "drupal_set_installed_schema_version('<module_machine_name>', <number_version>)"

Example:

drush ev "drupal_set_installed_schema_version('entityreference', 7002)"

For Drupal 8, 9, 10, 11

drush eval '\Drupal::service("update.update_hook_registry")->setInstalledVersion("MODULE", "930N")';

7. Get value of configuration in the site.

For Drupal 7

drush variable-get <key_configuration>

Example:

drush variable-get site_slogan
drush vget raven_release

For Drupal 8+

drush config-get <key_configuration>

Example:

drush config-get system.site

8. Set value of configuration in the site.

For Drupal 7

drush variable-set <key_configuration>

Example:

drush variable-set site_slogan 'Sharing drupal tutorials'
drush vset raven_release v2.0.1

For Drupal 8+

drush config-set <key_configuration> <child_key_configuration>

Example:

drush config-set system.site slogan 'Sharing drupal tutorials'
drush cset raven.settings release v2.0.1

You can find more Drush commands at https://drushcommands.com/

Reference: https://drushcommands.com

Comments