Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I chown to inherit parent directory's owner and group or the current account user

In terminal I know I can

chown whatever:whatever .*

What I want to do is dynamically set username and group to the current domain owner rather than root. Is there an easy way to do this?

Some background: I'm pushing to my server using Git as root then checking out to public_html. This makes any new files and directories owned by root:root. I want to add a line to hooks/post-receive to change the owner to the domain user rather than root but I don't want to have to specify the domain user explicitly if I don't have to.

like image 307
user844621 Avatar asked Nov 18 '25 06:11

user844621


1 Answers

The simples think I could think of is

chown -R `stat . -c %u:%g` *

You might also use $(...) instead of backticks here.

like image 69
kostix Avatar answered Nov 20 '25 20:11

kostix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!