how to keep file ownership while using tar
You want to "preserve" file attributes while doing tar -x
with the -p
switch. Obviously you need to be root for this to to have the desired result.
-p, --insecure, --preserve-permissions (x mode only) Preserve file permissions. Attempt to restore the full permissions, including owner, file modes, file flags and ACLs, if available,
Many POSIX systems also ship pax
, cpio
that can work as alternatives to tar
.