[Drupal] How to remove unused modules in a Drupal site with the help of Drush?

| | 2 min read

In a Drupal site, I was working on, I found that many of the modules were unused. Their presence was increasing the size of the site and consuming time when searching for useful info. So I thought of removing these modules.It makes our job a lot easier if we are using Drush Read on to know how to remove unused modules in a Drupal site with the help Drush.

We can find out the unused modules and manually remove them from the folder. But before removing them we have to make sure that it had not made any database change in the system. The module may be used earlier and simply disabled now for some reason and may be enabled later. So merely finding the disabled modules can cause problems. We have to find out only modules which were not installed in the first place. The followings are the steps to safely remove modules in a Drupal site.

  • Find out the list of all not installed modules using Drush and write it to a file. To do this first execute the following drush command to get the not installed modules list, each wrapped with single quotes and comma separated.

    • drush pm-list --no-core --pipe --type=module --status='not installed' | awk '{print "\x27" $1 "\x27" }' | tr "\n" ","

    Then take the mysql prompt. Change to your database using 'USE' command and execute the following command to write the output of our SQL query to a file.

    • tee /full/path/to/file

    Execute the following SQL query to get the not installed modules list. Copy and paste the modules list got from the above Drush command inside the brackets in the SQL query.

    • SELECT name, filename from system WHERE name IN ('comma','separated','list','of','modules','wrapped','in','single','quotes');

    Now we will get the list of all not installed modules in the file.

  • Check the list in the file and find out the fully unused modules and remove them manually from the folder. Do not remove any sub modules that have been put under a module even if it is found as not installed. Remove only the entire module folder and make sure that all its sub modules are not installed. Also don't remove any modules that are put directly under /modules. Only remove modules in the /sites/all/modules folder.

By doing the above steps you can easily find out the fully unused modules and can remove them physically without making any harm to the existing system.

 

 

Zyxware is a leading Drupal development company with a team of high expertise in Drupal custom module development services since 2006.