Skip to content

Compress All Files with XZ Compression

Problem

I wanted to compress all of the tar files in the directories for video processor application. Given the number of files, I did not want to do this one by one.

Solution

What I ended up doing was to create a script that I could run and it would loop through all of the files, which were all tar files, in the directory and compress them using xz compression.

GZ compress is the most common way, but after reading posts and articles, it was said that XZ compress can compress the tar files even smaller than GZ because it uses a different algorithm to do so.

The Script

#!/bin/bash

$(date)

for file in *
do
    echo "${file}"
    /usr/bin/xz -z "${file}" --threads=0
done

$(date)

Last update: 2022-10-02 Last update: Kenny Robinson, @almostengr