HOWTO:Change the UID and GID on files

Changing ownership of files when the UID/GID is obsolete or you need to change it for some other reason.

If you have changed or removed a UID for a user or GID a group, you must also change the flags set on the files belonging to these IDs. Otherwise you will have orphaned files.

To find the UID or GID for a user or group. You can use the ls with -ln. The -n will out put the numeric values rather than text. You can also use grep on the passwd and group files. The first number on the line is one you want.

Use find to locate and change the ownership of files. This command-line finds all files on the system owned by user UID and changes ownership to user newonwer or you can use a numeric value:

find / -uid UID -print | xargs -t chown newowner

This variation changes the group ownership:

find / -gid GID -print | xargs -t chgrp newgroup

NOTE: These examples assume a search of the entire directory tree, including all mounted file systems.

Do not run this command when the old or new user are in use. Better still drop down to single user mode.

Leave a Reply

Your email address will not be published. Required fields are marked *