Issue
I am using cp -rp
command to copy a directory /test
to the directory public_html
, preserving the destination ownership, like this:
cp -rp /home/test/ /home/user/public_html/test
As expected, the directory /test
is copied to /home/user/public_html/test
but only the /test
directory is preserving destination ownership. All other files inside /test
has the root:root
ownership:group.
I also tried the -a
option:
cp -a /home/test/ /home/user/public_html/
But the issue persists.
How do I do so the all the files and subdirectories inside the copied /test
folder also have the destination ownership?
Solution
I cannot comment to ask this, but it might also serve as an answer. Can you use rsync? In its default state it will copy files over but not change target permissions. If you wanted to preserve source permissions you could use the -p flag. Note that you’ll need a combination of flags to manage recursive copy and such.
https://linux.die.net/man/1/rsync
Answered By - sea0003 Answer Checked By - Marie Seifert (WPSolving Admin)