chown subfolders with current folder's owner and group
Solution 1:
You don't actually need to parse the output to remove the whitespace - you added that in your command! You can just format it as you like (with chown
's colon syntax) in the first place:
$ stat -c "%U:%G" .
zanna:unicorns
So just pass that to chown
with command substitution:
chown -R $(stat -c "%U:%G" .) .
Solution 2:
chown
, like chmod
, can use a reference:
chown [OPTION]... --reference=RFILE FILE...
Change the owner and/or group of each FILE to OWNER and/or GROUP. With
--reference, change the owner and group of each FILE to those of RFILE.
So:
chown --reference=/some/folder -R /some/folder