5

Currently I have to disable all of the ubercart modules in bulk, but there are too many of them to do it one at a time via the modules page. And doing it via drush doesn't disable every module related to ubercart sometimes. Is there a quick way to disable these modules via Drush in bulk matching a specific pattern?

1 Answer 1

6

Here's the drush recipe combined with a few other commands to disable modules in bulk:

drush pm-list | ack uc_ | ack Enabled | grep "\((.*)\)" | awk -F'(' '{print $2}' | awk -F')' '{print $1}' | xargs -i drush dis '{}' -y

Broken down:

  1. drush pm-list lists out all of your modules

  2. ack uc_ returns only the lines matching "uc_"

  3. ack Enabled returns only the enabled modules

  4. grep "\((.*)\)" matches the words in parentheses

  5. awk -F'(' '{print $2}' breaks up the line starting with the ( character

  6. awk -F')' '{print $1}' breaks up the line starting with the ) character

  7. xargs -i drush dis '{}' -y runs the returned result into drush disable command with the -y parameter for yes to all.


Thanks to greg_1_anderson, I updated it to be a bit shorter.

drush pm-list --status=enabled --pipe | grep 'uc_' | xargs -i drush pm-disable '{}' -y
5
  • This is cool, but could probably be simplified somewhat using drush pm-list --pipe | grep uc_. May 31, 2013 at 20:17
  • im sure it can be simplified, its just that im using what i know so far.. kinda long and barbaric i must say. May 31, 2013 at 20:19
  • drush pm-list --status=enabled --pipe will return only the enabled modules. Sorry, didn't notice you were awk'ing out the disabled modules. Also, you can drop the awk, since pm-list is outputting one module name per line and nothing more. May 31, 2013 at 22:39
  • For clarity/readability and making it easier to replace the pattern for non shell experts, perhaps doing it like PATTERN='uc_'; drush pm-list --status=enabled --pipe | grep ${PATTERN} | xargs -i drush pm-disable '{}' -y would be even better, if a bit more verbose.
    – Letharion
    Jun 1, 2013 at 14:15
  • I found I had to remove the xargs -i argument. I think it maybe should be -I (capitalised), but also --pipe returns string rather than separate lines, so that can happily be fed straight into drush pm-* Oct 15, 2014 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.