Breaking Systems For Fun And Profit
Image by MichaelGaida @ Pixabay

Disk Compression

Even though disk space is getting cheaper every year, the price per GiB is still more than zero. Saving disk space by minimizing wasted space should be high on the priorities list for every halfway decent systems administrator.

Running the following command will compress the space used on your root file system. If you have a separate file system for /home consider running the same command for that file system first.

1
find / -xdev -depth -type f -print0 | xz --files0

What it does

This command searches, depth-first, for every file on your root file system, and then compresses those files using xz.

Why it works

We never said it would transparently compress those files. It just replaces every single <file> with <file>.xz

The find command searches the root file system (find /), and only that file system (-xdev) depth-first (-depth) for all regular files (-type f), then prints a list of all files found using null-byte termination. This is then piped into xz as a list of files to compress (xz --files0)

TL;DR

  • Usable files
  • Wasted space
  • Fun