How do I change group ownership on folders created by a specific user?

6,381

Use find to do this:

find -type d -user $USER -exec chown :groupname {} +

it will finds all directories which belongs to the user $USER and changes the group of them to groupname.

  • Note: $USER is the current user you can change it with your desired one.
Share:
6,381

Related videos on Youtube

Ukuser32
Author by

Ukuser32

PHP web application developer

Updated on September 18, 2022

Comments

  • Ukuser32
    Ukuser32 almost 2 years

    I have user who has created a folder and so the permissions are user:user. I have now added user to group so my question is how can I update all folders created by user, as if I'd done chown user:group, but not all folders, because some have different owners. In effect - refresh folders to update the new group rights? Filezilla lists them still with the old user:group permissions.

    • Zanna
      Zanna about 7 years
      chown :group folder1 folder2 folder3? What's wrong with that?
    • Ukuser32
      Ukuser32 about 7 years
      Me being silly. I didn't know you could just use :group and didn't have to do user:group. I will leave this in case anyone else comes across it.
    • Ziazis
      Ziazis about 7 years
      Why use chown for just changing the group if there is an explicit command for that called "chgrp"?
  • muru
    muru about 7 years
    And I'd use the test for group ownership instead of user ownership (for cases like user:group2) (Also, -exec ... {} +)
  • Ravexina
    Ravexina about 7 years
    @muru I didn't get your point :/ (find updated)
  • muru
    muru about 7 years
    Right now files are owned by user:user, but some, according to OP, have different owners (say user2:user or user:group2). In that case, it'd make sense to only change :user to :group.
  • Ravexina
    Ravexina about 7 years
    @muru got it ;)