Shell command to output all plugins that exist across multiple wordpress installations I'm working on a server and need a complete list of plugins that are installed for all wp installations. I only need to know whether a plugin exists or not, it doesn't matter where it exists.

For example, given:

/siteA/wp-content/plugins/someplugin
/siteA/wp-content/plugins/anotherplugin

/siteB/wp-content/plugins/someplugin


I need the following result:

someplugin
anotherplugin


Here is the working command:

for i in $(find . -type d -name 'plugins' | grep 'wp-content/plugins$'); do find ${i} -maxdepth 1 -type d -exec sh -c 'for f do basename -- "$f"; done' sh {} + ; done | sort -u


Can this command be shortened?
If plugins only contain directories, list every unique entry in plugins:

shopt -s globstar
\ls -- **/wp-content/plugins |sort -u


Otherwise, include the final targets in the glob, plus a trailing slash to limit globbing to directories.  

That will yield paths relative to ., with trailing slash like siteA/wp-content/plugins/anotherplugin/.  We clean it up with basename (shorter, easier) or awk (faster if there are very many results EDIT: nope, awk is slower in spite of the algorithmic efficiency).

The backslash ignores aliases, just in case an aliased ls would mess up the output.

shopt -s globstar

# probably easier to remember
\ls -d -- **/wp-content/plugins/*/ |xargs -n1 basename -- |sort -u

# slower, fancier
\ls -d -- **/wp-content/plugins/*/ |awk -F/ '!u[$(NF-1)]++ { print $(NF-1) }'