1

I have more than 200 wordpress sites under /home2/blogname/public_html/ and I need to find what of these blogs don't have one subdir inside called "better-wp-security" under de plugins dir like: /home2/blogname/public_html/wp-content/plugins/

The reason is to know what blogs don't have the plugin "better-wp-security" for install it

Blogs that have the dir will show something like this:

/home2/blogname/public_html/wp-content/plugins/better-wp-security/

...so I need to list main dirs of blogs (/home2/blogname/) that don't have that directory.

How can I do that?.

6
  • Maybe find -type d /home2/*/public_html/wp-content/plugins/better-wp-security/ works?
    – 41754
    Aug 26, 2019 at 16:12
  • Then compare with a list of everything to get the list of which weren't found by the first command.
    – 41754
    Aug 26, 2019 at 16:12
  • Might want to sed out subdirectories of the plugin. Hope that helped.
    – 41754
    Aug 26, 2019 at 16:14
  • did not work properly. Listed tons of subdirs inside each /home2/*/public_html/wp-content/plugins/better-wp-security/. I need something like this: find /home2/*/public_html/wp-content/plugins/better-wp-security/ -type d | grep --invert-match /better-wp-security/ previous command don't work either :(
    – Hueznar
    Aug 26, 2019 at 16:34
  • My third comment was about sed'ing out subdirectories - by the name of slashes. I know it's surely not the most elegant way, but I think it should provide at least a quick way to get it done.
    – 41754
    Aug 26, 2019 at 16:36

1 Answer 1

3

You could do it with find, but you could also use a shell loop:

for dir in /home2/blogname/*
do
  [ -d "$dir"/public_html/wp-content/plugins/better-wp-security ] || printf '%s is missing a public_html/wp-content/plugins/better-wp-security directory\n' "$dir"
done

With GNU find:

find /home2/blogname -mindepth 1 -maxdepth 1 -exec sh -c \
  'test ! -d "$1"/public_html/wp-content/plugins/better-wp-security' findsh {} \; -print

This runs a small shell snippet on every entry under /home2/blogname -- beyond /home2/blogname itself, given -mindepth 1, and not on any subdirectories of /home2/blogname/*, given -maxdepth 1. The snippet checks to see whether the given directory has the listed subdirectory structure; if it does not, it passes the test and so is printed.

1
  • both solutions worked like a charm. Thank you everyone for all the help!! ^^
    – Hueznar
    Aug 26, 2019 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .