How to tar a directory preserving not only permissions, but ownership too

file-permissionsownershippermissionstar

I have to compress a directory using tar.gz preserving not only permissions, but ownership/groups too.

And, in this directory there are many files that belong to many users.

Best Answer

The owners of the file is preserved by default.

When extracting you need to use --same-owner flag. Such as tar --same-owner -xvf file.tar although the flag is only recommended for super users.

Check the tar man page.