TAR - retain SELinux context

by
Jeremy Canfield |
Updated: September 01 2021
| TAR articles
The --selinux option can be used to retain the SELinux context of files in a tar archive. In this example, example.tar contains the contents of the /etc directory and retains the SELinux context of the files in the /etc directory.
tar --selinux -cf /home/john.doe/example.tar /etc
Or, this might be a situation where it make more sense to use star instead of tar, because star automatically retains SELinux context.
Did you find this article helpful?
If so, consider buying me a coffee over at