I am new to unix. I want to write a script to change the ownership of files from root to myuser. Script which will check the ownership and if found as root will change it to myuser. The script should also log errors to a file. I know how to change ownership of files but not sure about putting the same in a script Please help.
Assuming you also want to change the group of the file (if not just drop the
Obviously to alter files own by root, you need to be root, so remember to run with
The simplest way of doing this recursively with find (finds files in directory structure that match various parameters). For instance
where -type f is used to avoid touching directories or other non-regular types of files (remove if not needed).
Of course you will need to be root to do this. You can just pack this up into a script, as
I don't think you will need to check for different errors - mostly it will just fail if you are not root.