[Drupal] How to find unused contributed-modules in a Drupal site?

| | 2 min read

Sometimes we may want to find all unused contributed modules in our site to clean up and all. In that case instead of manually checking all the modules from the sites/all/modules folder we can take it from the database system table.

We may want to find these unused contributed modules list to physically remove them from the sites/all/modules folder. But before removing them we have to make sure that none of its sub modules are currently using. So in order to find out the unused modules list we can do the following three steps.

  1. Find out all enabled contributed modules by querying it from the system table and write it to a file. To do this first execute the following command in the mysql prompt to write the output of our SQL query to a file.
    • tee /full/path/to/file

    Then execute the following SQL query to get all enabled modules list in ascending order.

    • SELECT filename FROM system WHERE status=1 AND filename LIKE "sites/all/modules%" order by filename ASC;
  2. Find out all disabled contributed modules by querying it from the system table and write it to a file. To do this first execute the following command in the mysql prompt to write the output of our SQL query to a file.
    • tee /full/path/to/file

    Then execute the following SQL query to get all disabled modules list in ascending order.

    • SELECT filename FROM system WHERE status=0 AND filename LIKE "sites/all/modules%" order by filename ASC;
  3. Compare both files to check whether any sub module of a module listed in the disabled modules list are also present in the enabled modules list and filter out only the fully unused modules.

By doing the above three steps you can easily find out the fully unused contributed modules and can remove them physically from the sites/all/modules folder 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.