When you compress text files or configuration scripts using the legacy lzma utility, checking those files later for modifications can be incredibly frustrating. If you use the standard diff tool on the archives, the terminal will simply tell you that the binary files differ, but it will not tell you what changed inside the text. To view the exact line-by-line differences between the data hidden inside the archives, you must use the lzdiff command.
How the lzdiff Command Works
The lzdiff utility acts as a specialized wrapper script. When you feed it two compressed .lzma files, it temporarily decompresses both files into your computer’s RAM, completely bypassing the hard drive. It then routes those uncompressed, human-readable text streams directly into the standard diff tool, which analyzes the text and prints the exact structural differences to your screen.
To compare two compressed server configuration files, simply run:
lzdiff server_config_v1.txt.lzma server_config_v2.txt.lzma
Reading the Output
Because the output is generated by the standard diff utility, it uses standard diff notation to tell you exactly how to edit the first file so that it perfectly matches the second file.
For example, you might see output like this:
5c5
< Port 8080
---
> Port 443
This output block means that on line 5, the first file (indicated by the < symbol) contains the text “Port 8080”. However, the second file (indicated by the > symbol) contains the text “Port 443”. The c in the middle stands for “change.”
Advanced Diff Flags
Because lzdiff relies on the underlying diff engine, you can actually pass standard diff formatting flags to it to change how the output is presented. If you find the standard notation confusing, you can use the -u (unified) flag.
lzdiff -u server_config_v1.txt.lzma server_config_v2.txt.lzma
The unified format is much easier for humans to read. It will print a few lines of context around the error and clearly mark deleted lines with a minus (-) sign and added lines with a plus (+) sign, making it immediately obvious what was changed between the two compressed versions.