7

I've uninstalled a lot of unnecessary modules recently through admin/modules/uninstall.
Now I want to understand what folders of the modules can be deleted from sites/all/modules.

I've tried drush pmi, but there is too much information.

How can I get list of folders which can be deleted safely now? Any drush command may be?

3

This works on Linux Machines. But you can do something similar on windows also I think.

Use the following command to get a list of disabled or uninstalled modules.

    drush pml --type=Module --status="disabled,not installed" --no-core 
--pipe | paste -s -d,

You will get a comma separated list like this

    admin_toolbar,admin_toolbar_tools,features,features_ui,entity_browser,
entity_browser_example,config_update,content_types_full_export

If you want to remove only the uninstalled module you can remove disabled from status option in the first query.

Once you have the comma separated list of un-installed modules you can pass it on to the drush pmi query like this.

drush pmi --format=csv --fields=path 
admin_toolbar,admin_toolbar_tools,features,features_ui,entity_browser,
entity_browser_example,config_update,content_types_full_export

You will get the ouput as

modules/admin_toolbar
modules/admin_toolbar/admin_toolbar_tools
modules/features
modules/features/modules/features_ui
modules/entity_browser
modules/entity_browser/modules/example
modules/config_update
modules/features_modules/content_types_full_export

You can use this to safely delete the folders :)

  • Unknown option: --status. when doing this in drush 8.1.12 – Nick Aug 18 '17 at 15:15
8

Use this:

drush pmi --fields=type,project,title,status,path --format=table|sort

This gives you a module list with five columns:

  • First is the type of project: module or theme.

  • Second one is the module project, for exampe views, logintoboggan, admin_menu, etc.

  • The third one is the installation status: enabled (in use), disabled (not in use but install info in DB) and not installed (it hasn't been installed yet or it have been already uninstalled).

  • Fourth column is module name. A module downloaded from drupal.org can have several modules inside (the downloaded module is the project and the inside modules are the real modules).

  • The fifth column is the path to the module.

With this information you can safely remove every project (second column) that all of its modules are in 'not installed' state.

For example, see this fragment list:

module  job_scheduler  Job Scheduler                enabled        sites/all/modules/contrib/job_scheduler                                                  
module  job_scheduler  Job Scheduler Trigger        not installed  sites/all/modules/contrib/job_scheduler/modules/job_scheduler_trigger                    
module  jquery_update  jQuery Update                enabled        sites/all/modules/contrib/jquery_update                                                  
module  l10n_client    Localization client          enabled        sites/all/modules/contrib/l10n_client                                                    
module  l10n_update    Localization update          enabled        sites/all/modules/contrib/l10n_update                                                    
module  languageicons  Language Icons               enabled        sites/all/modules/contrib/languageicons                                                  
module  ldap           LDAP Authentication          not installed  sites/all/modules/contrib/ldap/ldap_authentication                                       
module  ldap           LDAP Authorization - Roles   not installed  sites/all/modules/contrib/ldap/ldap_authorization/ldap_authorization_drupal_role         
module  ldap           LDAP Authorization           not installed  sites/all/modules/contrib/ldap/ldap_authorization                                        
module  ldap           LDAP Authorization - OG      not installed  sites/all/modules/contrib/ldap/ldap_authorization/ldap_authorization_og                  
module  ldap           LDAP Feeds                   not installed  sites/all/modules/contrib/ldap/ldap_feeds                                                
module  ldap           LDAP Help                    not installed  sites/all/modules/contrib/ldap/ldap_help                                                 
module  ldap           LDAP Query                   not installed  sites/all/modules/contrib/ldap/ldap_query                                                
module  ldap           LDAP Servers                 not installed  sites/all/modules/contrib/ldap/ldap_servers                                              
module  ldap           LDAP SSO                     not installed  sites/all/modules/contrib/ldap/ldap_sso                                                  
module  ldap           LDAP Test Module             not installed  sites/all/modules/contrib/ldap/ldap_test                                                 
module  ldap           LDAP User Module             not installed  sites/all/modules/contrib/ldap/ldap_user                                                 
module  ldap           LDAP Views                   not installed  sites/all/modules/contrib/ldap/ldap_views                                                
module  libraries      Libraries                    enabled        sites/all/modules/contrib/libraries 

You can safely remove the ldap module because all modules are not installed but not job scheduler because one of its modules is enabled.

  • I have error: Unknown options: --fields, --format (drush stable version 5.10.0 at Ubuntu). I think I need more fresh release. – Dimetry Mar 2 '15 at 16:10
  • Yes, you should update your drush installation – sanzante Mar 2 '15 at 16:15
  • I've made Drush update. Now I can execute command. It's not ideal solution, but now I see what folders can be deleted safely. ty – Dimetry Mar 2 '15 at 19:07
2

I have two suggestions for you on how to filter that drush command. One is with pipes and grep. The other is with the option arguments.

First off I think you want drush pml (lowercase "L", not lowercase "I").

(1) Pipes and Grep See the command below to list everything with status of "Not installed". The following may help give you a better picture of what's around your site. For example, here is what is there but "not installed" on my dev box.

$ drush pml | grep 'Not installed' | grep -v Core
 Administration                       Actions permissions (VBO) (actions_permissions)               Module  Not installed  7.x-3.2        
 BackgroundField                      BackgroundField (backgroundfield)                             Module  Not installed  7.x-1.5        
 Chaos tool suite                     Better Jump Menus (jump_menu)                                 Module  Not installed  7.x-1.4        
 Chaos tool suite                     Chaos Tools (CTools) AJAX Example (ctools_ajax_sample)        Module  Not installed  7.x-1.6        
 Chaos tool suite                     Chaos Tools (CTools) Plugin Example (ctools_plugin_example)   Module  Not installed  7.x-1.6        
 Chaos tool suite                     Custom content panes (ctools_custom_content)                  Module  Not installed  7.x-1.6        
 Chaos tool suite                     Custom rulesets (ctools_access_ruleset)                       Module  Not installed  7.x-1.6        
 Chaos tool suite                     Page manager existing pages (pm_existing_pages)               Module  Not installed  7.x-1.4        
 Chaos tool suite                     Stylizer (stylizer)                                           Module  Not installed  7.x-1.6        
 Chaos tool suite                     Term Depth access (term_depth)                                Module  Not installed  7.x-1.6        
 Chaos tool suite                     Views content panes (views_content)                           Module  Not installed  7.x-1.6        

Taken individually that is

drush pml \               # Shows table of modules/themes and their status
| grep 'Not installed' \  # Filters for any line WITH 'Not installed'
| grep -v Core            # Filters OUT any line containing string 'Core'

Given that you could do the following too :

$ drush pml  | grep 'Enabled'
$ drush pml  | grep 'Disabled'

(2) With options arguments to drush pml

You could also vary it up a bit with different arguments in the drush pml command

$ drush help pml
Show a list of available extensions (modules and themes).

Options:
 --core                                    Filter out extensions that are not in drupal core.                                             
 --no-core                                 Filter out extensions that are provided by drupal core.                                        
 --package                                 Filter by project packages. You can use multiple comma separated values. (i.e. --package="Core 
                                           - required,Other").                                                                            
 --pipe                                    Returns a whitespace delimited list of the names of the resulting extensions.                  
 --status=<disabled>                       Filter by extension status. Choices: enabled, disabled and/or 'not installed'. You can use     
                                           multiple comma separated values. (i.e. --status="disabled,not installed").                     
 --type=<module>                           Filter by extension type. Choices: module, theme.       

For example, you could use

$ drush pml --no-core --status="not installed" --type=module
 Package                                Name                                                                     Version             
 Administration                         Actions permissions (VBO) (actions_permissions)                          7.x-3.2             
 BackgroundField                        BackgroundField (backgroundfield)                                        7.x-1.5             
 Chaos tool suite                       Better Jump Menus (jump_menu)                                            7.x-1.4             
 Chaos tool suite                       Chaos Tools (CTools) AJAX Example (ctools_ajax_sample)                   7.x-1.6

***Note and caution:***  Always try this stuff on a development or vagrant box first. NEVER blindly do this to a production box.
  • I understand idea. Thanks. But how can I separate submodules? For example, I see Node Limit User as Not installed, but I can't delete node_limit folder because of I use main Node Limit – Dimetry Mar 2 '15 at 15:52
  • Can you give a named example of a module with submodules that you're trying to remove? Submodules are sometimes just nested inside the parent module. Though, if they're packaged together, it may not hurt to leave it be. If not authored well, some modules may use libraries or code in child folders. My gut is, if it's packaged together, leave it. – Rick Mar 2 '15 at 15:54
  • Otherwise, you could also do a dry run in a VM/Vagrant Box. Do you have a dev or throw away drupal install? Install the module, use devel_generate to make random content, remove and delete folders. See what breaks. Always best to test these things on throw away machines first! – Rick Mar 2 '15 at 15:56
2

You could also query the DB.

List of disabled but NOT uninstalled modules (can’t be deleted from the codebase)

drush sqlq "select name from system where type = 'module' and status = 0 and schema_version NOT IN (0, -1)"

List of disabled AND uninstalled modules (can be deleted from the codebase)

drush sqlq "select name from system where type = 'module' and status = 0 and schema_version IN (0, -1)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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