How to list, disable, enable multiple modules using drush commands

| | 3 min read

This article is about a few drush commands as well as Linux commands that helped ease my work at times while working on remote servers. Mostly while updating or upgrading. The need for bulk operations in drush is often never met except using complex Linux commands often involving 'sed'. Operations like disabling all non-core modules, enabling the disabled modules from a list, creating a list of all core and non-core modules in use and so on.

Before updating or upgrading any site, you must always document all the extensions on the site. The pml command is quite useful to list extensions as shown below.

//Lists all non core enabled modules
drush pml --no-core --type=module --status=enabled 

//Lists all enabled core modules
drush pml --core --type=module --status=enabled 

//Lists all disabled non core modules
drush pml --no-core --type=module --status=disabled 

//List all disabled core modules
drush pml --core --type=module --status=disabled 

// List all themes
drush pml --type=theme 

// List modules with available updates. --core --no-core can be specified here as well.
drush pm-updatestatus

These same commands can be combined with some useful Linux commands to document the outputs into text files. This will write the module's machine name into the txt file. For more details run "man cat" on your terminal.

drush pml --no-core --type=module --status=enabled --pipe | cat > enabled_noncore_modules.txt
drush pml --core --type=module --status=enabled --pipe | cat > enabled_core_modules.txt
drush pml --no-core --type=module --status=disabled --pipe | cat > disabled_noncore_modules.txt
drush pml --core --type=module --status=disabled --pipe | cat > disabled_core_modules.txt
drush pml --type=theme --pipe | cat > themes.txt
drush pm-updatestatus --pipe | cat > modules_to_update.txt

Run "cat <filename>" to output it on terminal. Example "cat list.txt". The --pipe argument is quite useful in providing a piped output to use in the following command.

Disable all non-core modules is quite easy. Disabling from a list of modules on the other hand may seem a bit more complex.

/* Disable all non-core modules */
drush pml --no-core --type=module --status=enabled --pipe | xargs drush dis -y

/* Disable all modules from a text file */
drush dis -y $(cat modules_list.txt) //OR
cat > modules_list.txt | drush dis -y
// The same can be applied for enabling

/* Update all modules from a text file */
drush pm-updatecode $(cat modules.txt) //OR
drush dl -y $(cat modules.txt)

The command "drush pm-updatestatus" works only in versions above 6. It is recommended to update to a version above this. You can find a simple global installation for latest version of drush here.

Drush provides the capability to write nested commands as seen earlier and so does Linux commands. You can mix and match with various commands.

drush en -y $(drush pml --no-core --type=module --status=enabled --pipe)
drush en -y $(drush pml --no-core --type=module --status=enabled --pipe | xargs cat > module_list.txt)
/* The above commands are just for testing, they will work but will not affect the database.*/

 Zyxware is a leading drupal development company in India that has operations in the US, UK, Canada, Australia, and the Middle East. Get in touch with us if you are looking to build a career in Drupal.