Use this script file to chown into the cPanel user defined by the path.

#!/bin/bash
THISUSER=`pwd | cut -d'/' -f 3`
echo
echo CHOWN all files to $THISUSER;
echo
find -exec chown $THISUSER:$THISUSER {} \;
chown :nobody /home/$THISUSER/public_html

For example, if the path is /home/username/this/file path, this will chown username.

Notice that the /home/username/public_html folder actually belongs to the nobody group or you will get errors.

We have to use find instead of chown directly because I found it would skip hidden files.

Installation

To install, run this in bash

cat > ~/chownthis.sh <<- EOM
#!/bin/bash
THISUSER=\`pwd | cut -d'/' -f 3\`
echo
echo CHOWN all files to \$THISUSER;
echo
find -exec chown \$THISUSER:\$THISUSER {} \;
chown :nobody /home/\$THISUSER/public_html
EOM
chmod +x ~/chownthis.sh

Operation

You can execute the script via

~/chownthis.sh