File permissions changed to root after distro switch

Q I recently switched distros from Xandros to Fedora. I transferred 3GB of data only to find that all the files in my home directory have root as both file owner and file group. Is there a script I can use to change all the permissions to my user name?

A If you've copied your home directory (which will look something like /home/dave) from one machine to another, the easiest way to restore ownership on that directory is to do a recursive chown as root on /home/dave with the correct ownership, recursively changing the user and group. It should be safe to perform this on your home directory, as it usually only contains files and directories owned by the user and group of the user whose home directory it is.

chown -R macdaddy:macdaddy / home/macdaddy

If you have multiple files and directories owned by different users and groups, you will need to do a search and replace to change the ownership. So if user 'dave' has numerous files and directories throughout /var/www/html and you want to change the ownership of those files to user and group 'bigmac', you could chown -R directories to change ownership. The problem with this is that it may change ownership of files that you didn't want it to. In this case, use the find command to perform the search and replace on the ownership, ensuring that those directories not owned by Dave are left as they are:

find /var/www/html -user dave -group dave -exec chown bigmac:bigmac {} \;

This will find any files and directories within /var/www/html belonging to user and group dave, then change the ownership to bigmac. The {} gets replaced with the files and directories found matching the -user and -group criteria, and the \; is necessary to escape the ; to the shell and to tell find that the argument list has finished. So, assuming you have a standard home directory, the easiest way to change ownership in one go would be to use the chown -R command. Keep in mind that this method is not applicable for all locations on the filesystem though!

Back to the list