The command stat -c '%U:%G' home/userB/finalfolder
returns the owner and group of the finalfolder
, separated by a colon. This is just the format that chown
needs. Thus, use:
chown "$(stat -c '%U:%G' home/userB/finalfolder)" /home/userB/finalfolder/abc.bin
This works with GNU stat
which should be fine because you are on centos.