FreeKB - tar (random tips)
Linux Commands - tar (random tips)

The tar command can be used to create or extract an archive. 

Appended files to an archive

The -r or --append option can be used to append files to a tar archive. In this example, the contents of the /var directory is appended to example.tar.

tar -rf /home/john.doe/example.tar /var


Retain SELinux context

The --selinux option can be used to retain the SELinux context of a file. In this example, example.tar contains the contents of the /etc directory and records the SELinux context of the files in the /etc directory.

tar --selinux -cf /home/john.doe/example.tar /etc 


Compression level

Tar does not have an option to specify the compress level, such as 1 for the least compression, or 9 for the most compression. However, you can create a tar archive, and then use gzip or bzip2 to specify the compression level. For example, a tar archive of the tmp directory can be created, and then the tmp.tar archive can be compressed at level 9.

tar -cf /tmp
gzip -9 tmp.tar


Exclude directories

The --exclude option can be used to exclude directories from being included in the tar archive. In this example, a tar archive named example.tar is created, and the tar archive will contain everything below the /home directory except for anything at and below /home/john.doe.

tar -cf example.tar --exclude /home/john.doe /home


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 13c67 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |