Copying stickbits

Hello everyone,
I have tried copying a directory having a sticky bit set to another directory. The source directory was copied with the sticky bit but the contents (i.e: other files and directories) within the directory which another user had created changed ownership to show as i had created it.This is disturbing.
How can i copy files across directories and at the same time retain the original permissions including special permissions.The contents are within my home_dir.
command i used was :

sudo find . -depth | cpio -pudmv ~/cpio_test

NB: I managed to get away with it when i copied it using root.

sudo when prefixing a pipeline only applies to the first command. cpio need root or at least the RBAC privileges required to set owners, stick-bits and similar sensitive actions.
You can use something like this:

sudo find . -depth | sudo cpio -pudmv ~/cpio_test

or

sudo ksh -c "find . -depth | cpio -pudmv ~/cpio_test"
1 Like