how to keep file ownership while using tar how to keep file ownership while using tar unix unix

how to keep file ownership while using tar


Supply the option --same-owner to tar while extracting.

tar --help tells:

   --same-owner          create extracted files with the same ownership


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.