How to list, disable, enable multiple modules using drush commands
BY abhai.sasidharan
3 years ago
0 comments comment

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 disable all non-core modules, enable the disabled modules from a list, create 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 in 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.*/



on 14th December 2012 / by thomas.john
The default method of changing a Drupal theme using the graphical Admin interface is familiar to most Drupal users. However a Drupal user is limited to changing only one theme at a time using this method and it is also slightly time consuming. What if you want to enable more then one theme at a time? Drupal provides a quicker way to change the theme using the bash command line. Read on to know how to enable multiple Drupal themes using the bash command line Drupal Bash Drupal Themes Drupal Theming Drush Leave a reply Your email address will not be published. Required fields are marker *

on 13th May 2013 / by meera.l
As the World wide web is starting to resemble the wild wild west, you have to ensure that your Drupal site is always up to date. If you are ignoring the security updates of Drupal, then you are simply making your Drupal site vulnerable to the worst enemy of all - Negligence. Updating a Drupal site requires time and effort which is why most people ignore it. Here is a quick way to update your Drupal site using Drush and Hacked module. Web Development Drupal Drupal Updates Drush Leave a reply Your email address will not be published. Required fields are marker *

on 02nd January 2015 / by emily.mathew
It is important to keep our drupal site up-to-date. New releases of contributed modules and Drupal core come out periodically to address critical security fixes, and it's important to stay on top of updates as they are released. It is difficult to download the latest version of each module separately and then remove the old one from the sites/all/modules folder and put the the new one in that place and all. Drush comes to help us in updating the modules in an easy way. The following are the steps to update the non hacked modules using drush Drupal Drush Leave a reply Your email address will not be published. Required fields are marker *
Leave a reply
Your email address will not be published. Required fields are marker *

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
The content of this field is kept private and will not be shown publicly.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.