The xz compression method is yet another popular compression method used on Linux. On average, xz compression does the best job out of all three compression methods in reducing (compressing) the file sizes.
You can compress an archive with xz compression by using the -J option with the tar command as follows:
tar -cJf compressed_name archive_name
Notice here we use the uppercase letter J with xz compression. So to compress the scripts.tar archive into an xz-compressed archive named scripts.tar.xz, you first need to change to the /root/backup directory and then run the following command:
root@ubuntu-linux:~/backup# tar -cJf scripts.tar.xz scripts.tar
Now if you list the contents of the backup directory, you will see the newly created xz-compressed archive scripts.tar.xz:
root@ubuntu-linux:~/backup# ls
scripts.tar scripts.tar.bz2 scripts.tar.gz scripts.tar.xz
Let's run the file command on the xz-compressed archive scripts.tar.xz:
root@ubuntu-linux:~/backup# file...