0

I have a directory with about 100 sub directories. Some of these sub directories are "Wordpress folders" others are not. What I would like to do is change the ownership of the themes and plugin directories inside the "Wordpress folders". I'm using this command to get the list of these directories:

find . -maxdepth 3 -type d | grep 'wp-content/themes\|wp-content/plugins'

How could I make change the ownership of all plugins and themes subdirectories?

pa4080
  • 29,351
  • 10
  • 85
  • 161
koni_raid
  • 3,292
  • 2
  • 22
  • 28
  • Could you please add a little more detail? What *exactly* did you do, what did you want to achieve and what happened instead? Did you encounter any warning or error messages? Please reproduce them in their entirety in your question ([edit]). You can select, copy and paste terminal content and most dialogue messages in Ubuntu. (see [How do I ask a good question?](https://askubuntu.com/help/how-to-ask)) – dessert Nov 17 '17 at 08:55
  • I used this command to get a list of the Wordpress folders: `find . -maxdepth 3 -type d | grep 'wp-content/themes'` – koni_raid Nov 20 '17 at 08:48
  • You should rather use `find . -maxdepth 3 -type d -path "*wp-content/themes*"` and always add additional information directly to your question with [edit], but that still doesn't clarify much. What's the overall problem, what *exactly* do you want to achieve? Does the `find` command list all the directories you want to modify? – dessert Nov 20 '17 at 08:55
  • 1
    Add how to identify your folders. Is there any reason why you can't just do `chown -R user:group */wp-content/themes`? – muru Nov 20 '17 at 09:08
  • You could modify your command in [this way](https://stackoverflow.com/a/5249797/6543935): `find . -maxdepth 3 -type d -regextype posix-extended -regex '.*wp-content/(themes|plugins)' -exec echo chown -R User:Group {} \;`. Tweak the `User:Group` part. When the output looks sufficient remove `echo` to do the changes. – pa4080 Nov 20 '17 at 09:22

1 Answers1

2

You could modify your command in this way:

find . -maxdepth 3 -type d -regextype posix-extended -regex '.*wp-content/(themes|plugins)' -exec echo chown -R user:group {} +
  • Change the user:group pair with the actual user and group.
  • Change the end of the find command from {} + to {} \; to output separate commands for each directory - it could be more easy to read (reference).
  • Remove echo to do the changes.

I'm afraid that @muru's solution is more elegant :) It could be modified in this way:

echo chown -R user:group */wp-content/{themes,plugins}
  • Change the user:group pair with the actual user and group.
  • Remove echo to do the changes.
pa4080
  • 29,351
  • 10
  • 85
  • 161