How to list, disable, enable multiple modules using drush commands
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=2YmREnrP
BY abhai.sasidharan
3 years ago
Drush
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.*/

RELATED ARTICLE

more_horiz
close

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 First we have to install drush on your server. Drush is a command line interface for accessing and working with Drupal After installing Drush lets check out all the existing themes in our Drupal site Type the following command from your Drupal server~/drush/drush pm-list --type=theme In sites/all/themes folder typedrush pm-list --type=theme This will display all themes in following order Package Name Status Version To enable a single theme with confirmation Type the following command from your Drupal server~/drush/drush pm-enable themename eg: ~/drush/drush pm-enable vert In sites/all/themes folder typedrush pm-enable themename eg: drush pm-enable business_blog To enable a single theme without confirmation Type the following command from your Drupal server~/drush/drush pm-enable themename --yes eg: ~/drush/drush pm-enable vert --yes In sites/all/themes folder type drush pm-enable themename --yes eg: drush pm-enable black_blog --yes List all themes with the associated info Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' ' In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' ' Cut each column Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' '| cut -f1 -d' ' ~/drush/drush pm-list --type=theme | tr -s ' '| cut -f2 -d' '~/drush/drush pm-list --type=theme | tr -s ' '| cut -f3 -d' ' In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' '| cut -f1 -d' ' drush pm-list --type=theme | tr -s ' '| cut -f2 -d' ' drush pm-list --type=theme | tr -s ' '| cut -f3 -d' ' Display all theme names Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// Write all the themes to a themelist file Type the following command from your Drupal server~/drush/drush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// &gt; themelist In sites/all/themes folder typedrush pm-list --type=theme | tr -s ' ' | sed s/.*\(//| sed s/\).*// &gt; themelist Make sure that the file contains only theme name and not any other content. You can edit the file using following commandsless themelist nano themelist wc -l themelist Display all the themes from themelist file for i in `cat themelist`; do echo $i; done Enable all the themes (with confirmation required) Type the following command from your Drupal server for i in `cat themelist`; do ~/drush/drush en $i; done In sites/all/themes folder typefor i in `cat themelist`; do drush en $i; done Enable all the themes (without confirmation) Type the following command from your Drupal serverfor i in `cat themelist`; do ~/drush/drush en $i --yes; done In sites/all/themes folder typefor i in `cat themelist`; do /drush en $i --yes; done Hope you have find this article useful. Feel free to give your feedback via the comment form below . Drupal Bash Drupal Themes Drupal Theming Drush Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

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. We had recently done a string of Drupal updates on some sites and they went pretty smoothly without any hassle. This is possible if you use Drush and the Drupal Hacked module. Here are the steps you have to follow to update your site with Drush. Note: Before performing any major changes on your Drupal site, remember to take a complete database backup of your site and if possible a codebase backup using a VCS Steps to update Drupal using Drush Install Drush. To check any of the module or core is hacked, you can use the Hacked module. Download and enable hacked module using the following command. drush dl hacked drush en hackedNow to find the status of modules and Drupal core run the following command. drush hlpTo compare the current version of the module in your site, with the one downloaded from www.drupal.org, run the following command. drush hacked-details 'module name'To find the difference between the files use the following command. drush hacked-diff 'module-name'If you don't need to update the modified modules, lock them using the following command. drush hacked-lock-modifiedRun the following command to update. #Update all update available modules other than locked modules. drush pm-update or #Update specified module only. drush up 'module-name'After update you can disable hacked moule using drush pm-disable hackedReference: http://fuseinteractive.ca/blog/hacked-module-drush-integration We would love to hear your feedback regarding the article. Please use the comments form below Web Development Drupal Drupal Updates Drush Leave a reply Your email address will not be published. Required fields are marker *
more_horiz
close

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 Run the following command in the command prompt under our projects directory. drush hlp &gt; status The above command will create a file 'status' which list all the modules with title, name, current version and its status. If status is Unchanged that means the module is not hacked and we can simply update it with out any problem. Update the modules that are not hacked by running the following command under our projects directory. drush up &lt;module name&gt; The above command will download the latest version and replace the old one in the sites/all/modules directory. If it shows any database change then also run update.php in the browser. By doing the above two steps you can easily update the non hacked modules. 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.