Return to Snippet

Revision: 13942
at May 13, 2009 23:33 by zachharkey


Updated Code
# Change the ownership of all files owned by one user. 
# Finds all files in /home owned by UID 1056 and changes to 2056.
# See: http://www.commandlinefu.com/commands/view/892/change-the-ownership-of-all-files-owned-by-one-user.
find /home -uid 1056 -exec chown 2056 {} \;

# Changing files ownership in a directory recursivley from a user to another
# See: http://www.commandlinefu.com/commands/view/414/recursive-ownership-change

chown -cR --from=olduser:oldgroup newuser:newgroup *

find path/to/dir -user fred -exec chown barney '{}' \;

# Or, if you wish to change also the group name of the file's ownership 
# to match the new user name, find the new user's group name and plug it into this:

find path/to/dir -user fred -exec chown barney:barneygroup '{}' \;

# Caveats: 
# 1. Not only will this change the files under the specified directory,
#    but it will change the directory itself, if the ownership matches.
# 2. Changing files owned by root can hose your system.
# See: http://www.linuxforums.org/forum/linux-programming-scripting/132312-changing-all-files-owned-root-assigned-other-user.html

Revision: 13941
at May 13, 2009 23:09 by zachharkey


Initial Code
find topdirectoryname -user fred -exec chown barney '{}' \;

# Or, if you wish to change also the group name of the file's ownership to match the new user name, find the new user's group name and plug it into this:

find topdirectoryname -user fred -exec chown barney:barneygroup '{}' \;

Initial URL

                                

Initial Description
<http://www.commandlinefu.com/commands/using/chown>

Initial Title
Change ownership of all files owned by user1 to user2

Initial Tags
unix

Initial Language
Bash