Skip to content

Instantly share code, notes, and snippets.

@grahambates
Created November 6, 2013 12:06
Show Gist options
  • Save grahambates/7335051 to your computer and use it in GitHub Desktop.
Save grahambates/7335051 to your computer and use it in GitHub Desktop.
Delete any unused Drupal module directories. Assumes '/sites/all/modules/contrib' etc. directory structure, hence depth of 5. Change this if required. Removes any directories that contain no enabled modules, taking into account sub-modules.
drush sqlq "SELECT DISTINCT SUBSTRING_INDEX(filename , '/', 5) dir
FROM system
WHERE status = 0
AND type = 'module'
AND filename NOT LIKE 'modules/%'
HAVING dir NOT IN (
SELECT SUBSTRING_INDEX(filename , '/', 5)
FROM system
WHERE status = 1
);" | xargs rm -rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment