Posted By

zachharkey on 05/13/09


Tagged

unix


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

thehighlandway


Change ownership of all files owned by user1 to user2


 / Published in: Bash
 

  1. # Change the ownership of all files owned by one user.
  2. # Finds all files in /home owned by UID 1056 and changes to 2056.
  3. # See: http://www.commandlinefu.com/commands/view/892/change-the-ownership-of-all-files-owned-by-one-user.
  4. find /home -uid 1056 -exec chown 2056 {} \;
  5.  
  6. # Changing files ownership in a directory recursivley from a user to another
  7. # See: http://www.commandlinefu.com/commands/view/414/recursive-ownership-change
  8.  
  9. chown -cR --from=olduser:oldgroup newuser:newgroup *
  10.  
  11. find path/to/dir -user fred -exec chown barney '{}' \;
  12.  
  13. # Or, if you wish to change also the group name of the file's ownership
  14. # to match the new user name, find the new user's group name and plug it into this:
  15.  
  16. find path/to/dir -user fred -exec chown barney:barneygroup '{}' \;
  17.  
  18. # Caveats:
  19. # 1. Not only will this change the files under the specified directory,
  20. # but it will change the directory itself, if the ownership matches.
  21. # 2. Changing files owned by root can hose your system.
  22. # See: http://www.linuxforums.org/forum/linux-programming-scripting/132312-changing-all-files-owned-root-assigned-other-user.html

Report this snippet  

You need to login to post a comment.