The following command will allow you to change the ownership of a directory along with all files and sub-directories without changing permissions.
Changing the ownership can be done very easily. Often it can be a requirement to change the owner of a directory if you want to allow apache to read and write to a directory, but don’t want to give the directory full open access.
chown -R user /directory/path
The chown command is used to change the ownership of the directory. Adding -R to this command stands for recursive. This is a common variable used for command line functions. This stands for recursive, which means it will go through all sub directories and files and perform the same action that it performed on the parent.
When adding the path make sure to make it the full directory from the root to avoid any issues while using relative paths. Regardless of your current directory using a slash “/” at the start of the directory will make the command start at root and work its way into the directory defined.